Changes Tracker
I have decided to give such a title after realizing how changes in life are important. Fortunately, in the world of electronics, these changes can be quantified and also can be used in control systems. This instructable will demonstrate how different sensors can be used to gather data from the world (listening and tracking changes), feeding the data into a micro-controller (ATmega 328P- Arduino Uno Version)and then how the data collected be used again to control the world (actuators). It consists of motion detectors, solar radiation sensors, temperature sensors, hall effect sensors, radio frequency detection, etc.
Gathering the Necessary Components
Grab all the sensors and actuators you might need. For my sensors I used;
- Hall effect sensor (A1325) - Magnetic field
- Temperature sensor (LM35) - Temperature
- Light Dependent Resistor - Solar radiation
- Ultrasonic sensor (Adafruit) - Distance Measurement
- Air Moisture sensor (Adafruit) - Humidity
- Infra-red sensors (Adafruit) - Motion Detector
- Soil Moisture Sensor (Adafruit) - Soil moisture content
- Pre-amp microphone - Sound
- Remote controlled car - RF Detector
For the actuators I used;
- Green and Red LED
- Piezo buzzer
- Electric fan
- Servo Motor
- General motor
Other components include;
- Breadboard with a 12V power supply
- Arduino Uno with a cable
- Cups with dry and wet soil
- Capacitors, Resistors,JFET Transistor and diodes
- Multiplexer (DG526)
- Connecting Wires
1-2 Testing the Sensors and Actuators
After gathering enough sensors you might find out you will run out of pins to connect on the Arduino Uno, so probably you might use a multiplexer in reading especially the analog sensors. You can find many tutorials on how to connect different analog sensors to a multiplexer from the internet, in case you don't find them, feel free to ask me. You can use a small breadboard for testing the sensors and for also controlling the actuators.
Testing More Sensors and Actuators
It might look boring but this will act as an exercise on how to program the Arduino for analog and digital reading and also the digital and analog (PWM) writing. For my case I connected all the sensors to the multiplexer and used the single output of the multiplexer as a analog input to the Arduino and wrote a code that reads and display all the values. The actuators I connected directly to the Arduino.
Connecting All the Components Together
With time I will provide a circuit diagram and a comprehensive explanation of the connections I made, this is just to give you an idea. For those advanced in coding you can follow how I made my connections from the sketch provided in the next step. With these connections you can,
- Read the voltage generated the LDR (connected in a voltage divider manner) and convert it to a vague reading of solar radiation incident on it (LDR can be replaced by a photodiode or phototransitor).
- Read the temperature being measured by the LM35 and program the Arduino to serially display on the Monitor or LCD (16 by 2 LCD).
- Detect any strong magnetic field around the Changes Tracker area, you can input a threshold value and use that value to turn on a buzzer or fan.
- Detect sound using the pre-amp microphone or even using the piezzo buzzer and use it to control a servo motor
- Calculate the distance an obstacle is away from the Changes Tracker using the Ultrasonic detector (range of 5 meters) and display it serially.
- Detect motion using four infra-red sensors positioned on four sides (NEWS) and can then detect the direction where the intruder is coming from. You can set a threshold to trigger an alarm.
- Switch on and off LEDs depending on the radio frequency sensed. For the RF I just bought a remote controlled toy car and took out the RF components and connected them to the Arduino
- Detect the values of soil moisture content and air moisture (humidity) and even control an irrigation sprinkler. Watch out my next instructable!!!
Arduino Sketch
FOR THE ULTRASONIC SENSOR
/*James at it again, this time around using the Ultrasonic
Sensor to measure distance*/
const int trigPin = 2;
const int echoPin = 3;
int redLed = 12;
int greenLed = 11;
int maxRange = 50; // Maximum range needed
int minRange = 0; // Minimum range needed
long duration;
long distance;
void setup() {
Serial.begin (9600);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(redLed, OUTPUT);
pinMode(greenLed, OUTPUT);
}
void loop() {
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
//Calculate the distance (in cm) based on the speed of sound.
distance = duration/58.2;
if (distance >= maxRange || distance <= minRange){
Serial.println("It is very safe");
digitalWrite(greenLed, HIGH);
digitalWrite(redLed, LOW);
}
else {
Serial.print("James, there is a breach at ");
Serial.print(distance);
Serial.println("cm.There is an INTRUDER!!!!");
digitalWrite(greenLed, LOW);
digitalWrite(redLed, HIGH);
}
//Delay 50ms before next reading.
delay(50);
}
FOR THE INFRARED SENSOR
/*James at it again this time around trying to sense
infra-red radiation detected around the house for use in burglar alarms*/
int IRA = 2;
int IRB = 3;
int IRC = 4;
int IRD = 5;
int left = 6;
int right = 7;
int front = 8;
int back = 9;
int buzzer = 10;
int safe = 11;
void setup()
{
Serial.begin(9600);
for (int pinNumber = 2; pinNumber<6; pinNumber++){
pinMode(pinNumber, INPUT);
digitalWrite(pinNumber, LOW);}
for (int pin = 6; pin<12; pin++){
pinMode(pin, OUTPUT);
digitalWrite(pin, LOW);}
Serial.println("Hie James");
}
void loop()
{
if(digitalRead(IRA)==LOW)
{ digitalWrite(front, HIGH);
digitalWrite(safe, LOW);
digitalWrite(buzzer, HIGH);
Serial.println("Intruder from the FRONT!!!");
}
else{digitalWrite(front, LOW);
digitalWrite(safe, HIGH);
digitalWrite(buzzer, LOW);}
//delay(10);
if(digitalRead(IRB)==LOW)
{ digitalWrite(back, HIGH);
digitalWrite(safe, LOW);
digitalWrite(buzzer, HIGH);
Serial.println("Intruder from the BACK!!!");
}
else{digitalWrite(back, LOW);
digitalWrite(safe, HIGH);
digitalWrite(buzzer, LOW);}
//delay(10);
if(digitalRead(IRC)==LOW)
{ digitalWrite(left, HIGH);
digitalWrite(safe, LOW);
digitalWrite(buzzer, HIGH);
Serial.println("Intruder from the LEFT!!!");
}
else{digitalWrite(left, LOW);
digitalWrite(safe, HIGH);
digitalWrite(buzzer, LOW);}
//delay(10);
if(digitalRead(IRD)==LOW)
{ digitalWrite(right, HIGH);
digitalWrite(safe, LOW);
digitalWrite(buzzer, HIGH);
Serial.println("Intruder from the RIGHT!!!");
}
else{digitalWrite(right, LOW);
digitalWrite(safe, HIGH);
digitalWrite(buzzer, LOW);}
//delay(10);
}
Grand Unifying Code
FOR MULTIPLEXING
//James at it again, this time around trying to unify all
the sensors so that they work for a common goal. Awesome stuff here!!!
const int trig = 2; // pin where ultrasonic trig pin is connected
const int echo = 3; // pin where ultrasonic echo pin is connected
const int a = 4; // LSB of the mux selection code
const int b = 5; // LSB 2 of the mux select line
const int c = 6; //MSB 2 of the select line for the mux
const int d = 7; // MSB of the select line for the mux
const int generator = 9; // data line for the generator
const int buzzer = 10; // output sound using the buzzer
const int greenLed = 11; // green led connected on this pin
const int redLed = 12; // red led connected here
const int fan = 13; // fan is connected on this pin
const int muxdata = A0; // output of the multiplexer data line
const int rftransmitter = A1; //input of the radio frequency transmitter
#include // Calling the servo motor library
Servo servo; // Giving a name to the pin attached to servo
int lighthreshold = 500; // Threshold for the LDR sensor
int magneticthreshold = 500; // Threshold for the Hall-effect sensor (A1325)
const float tempethreshold = 25.0; // Baseline temperature for the LM35 temperature sensor
int switchState = 0; // Checking the state of the switch as a pressure sensor
int soilmoisturethreshold = 500; // Checking the analog soil moisture content
int smcState = 0; // Checking the state of the moisture content digitally
int irdistance = 30; // Setting the range of the inrared sensors
int maxRange = 200; // Maximum range needed in centimetres
int minRange = 0; // Minimum range needed in centimetres
long duration; // Pulse wise of the sent signal
long distance; // distance travelled
int muxVal, rfVal; // Reading the state of the inputs
int time = 500;
void setup()
{
servo.attach(8); // Attaching my servo motor pin to pin 88
Serial.begin(9600); // baud rate for the communication between the laptop and the arduino
pinMode(trig, OUTPUT); // declaring as an output pin
pinMode(echo, INPUT); // declaring as an INPUT pin
pinMode(a, OUTPUT); // declaring as an output pin
pinMode(b, OUTPUT); // declaring as an output pin
pinMode(c, OUTPUT); // declaring as an output pin
pinMode(d, OUTPUT); // declaring as an output pin
pinMode(generator, OUTPUT); // declaring as an output pin
pinMode(buzzer, OUTPUT); // declaring as an output pin
pinMode(greenLed, OUTPUT); // declaring as an output pin
pinMode(redLed, OUTPUT); // declaring as an output pin
pinMode(fan, OUTPUT); // declaring as an output pin
pinMode(muxdata, INPUT); // declaring as an INPUT pin
pinMode(rftransmitter, INPUT); // declaring as an INPUT pin
Serial.println("Zvaunondiita so!!!"); //Just a welcome message for my Raspberry Pi
digitalWrite(a, LOW);
digitalWrite(b, LOW);
digitalWrite(c, LOW);
digitalWrite(d, LOW);
}
void loop()
{
digitalWrite(a, LOW);
digitalWrite(b, LOW);
digitalWrite(c, LOW);
digitalWrite(d, LOW);
delay(time); //not sure if this delay is strictly necessary
int readInZero = analogRead(muxdata); // read the arduino input pin the Dg526 is using
float solRad = (readInZero*1000.0/1023.0);
Serial.print("Solar radiation is ");
Serial.print(solRad); //use the result
Serial.println(" watts per square metre");
digitalWrite(a, HIGH);
digitalWrite(b, LOW);
digitalWrite(c, LOW);
digitalWrite(d, LOW);
delay(time); //not sure if this delay is strictly necessary
int readInOne = analogRead(muxdata); // read the arduino analog input pin
float pressure = (readInOne*1012.2/1023.0);
Serial.print ("Atmospheric Pressure reads ");
Serial.print(pressure); //use the result
Serial.println(" kPa");
digitalWrite(a, LOW);
digitalWrite(b, HIGH);
digitalWrite(c, LOW);
digitalWrite(d, LOW);
delay(time);
int readInTwo= analogRead(muxdata);
float temp = (readInTwo*500.0/1203.0);
Serial.print("Ambient temperature reads ");
Serial.print(temp); //use the result
Serial.println(" degree Celsius");
digitalWrite(a, HIGH);
digitalWrite(b, HIGH);
digitalWrite(c, LOW);
digitalWrite(d, LOW);
delay(time);
int readInThree= analogRead(muxdata);
Serial.print("The Wind Speed is ");
float windspeed = (readInThree*2.0/1023.0);
Serial.print(windspeed);
Serial.println(" metres per second"); //use the result
digitalWrite(a, LOW);
digitalWrite(b, LOW);
digitalWrite(c, HIGH);
digitalWrite(d, LOW);
delay(time);
int readInFour= analogRead(muxdata);
float smc = (readInFour*100.0/1023.0);
Serial.print("Soil Moisture Content is ");
Serial.print(smc);
Serial.println(" %"); //use the result
}
Last Box Standing
So what can be done? This idea can be used to:
- Make a automatic weather station
- Home alarm system
- Can be used for educational systems
Look out for a comprehensive instructable for this CHANGES TRACKER... If you need help urgently feel free to contact me.