Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 44

Smoke Detection using MQ-2 Gas Sensor page 56 total

The smoke sensor has a built-in potentiometer that allows you to adjust the sensor sensitivity
according to how accurate you want to detect gas.

Hardware components

Arduino UNO & Genuino UNO


× 1

Breadboard (generic)
× 1

MQ-2 Smoke detection sensor


× 1

Male/Female Jumper Wires


× 1

5 mm LED: Red
× 1

5 mm LED: Green
× 1

Buzzer
× 1

Resistor 221 ohm


× 3

1
Pin Wiring MQ-2 sensor code

The MQ-2 sensor has 4 pins. /*******

Pin-------------------------------------Wiring to Arduino Uno All the resources for this project:


https://www.hackster.io/Aritro

A0-------------------------------------Analog pins *******/

int redLed = 12;


D0-------------------------------------Digital pins int greenLed = 11;
int buzzer = 10;
GND-----------------------------------GND int smokeA0 = A5;
// Your threshold value
int sensorThres = 400;
VCC------------------------------------5V
void setup() {
pinMode(redLed, OUTPUT);
Connection schematic diagram
pinMode(greenLed, OUTPUT);
pinMode(buzzer, OUTPUT);
pinMode(smokeA0, INPUT);
Serial.begin(9600);
}

void loop() {
int analogSensor = analogRead(smokeA0);

Serial.print("Pin A0: ");


Serial.println(analogSensor);
// Checks if it has reached the
threshold value
if (analogSensor > sensorThres)
{
digitalWrite(redLed, HIGH);
digitalWrite(greenLed, LOW);
tone(buzzer, 1000, 200);
}
else
{
digitalWrite(redLed, LOW);
digitalWrite(greenLed, HIGH);
noTone(buzzer);
}
delay(100);
}

2
Automatic Pet Watering System
The automatic watering system simple just read the water level in the water bowl with a HC-
SR04 ultra sonic sound sensor. It measure the distance to the surface of the water. If the level is less
then 3cm for more than 30sec it triggers a 5V relay whit a NO-contact . The relay are controlling a
12VDC supply to a mini watering pump in the water tank.

Hardware components

General Purpose Transistor NPN


× 1

SparkFun Arduino Pro Mini 328 - 5V/16MHz


× 1

Relay (generic)
× 1

RGB Diffused Common Cathode


× 1

Arduino Crystal Liquid Display


× 1

Schematics

3
Code for Automatic Pet Watering System

//Automatic watering ystem// void loop()


{

const int trigPin = A3;


const int echoPin = A2;

int rele = 3;
int normaldrift = 5;
int fyller = 8; // LEVEL SENSOR
//
long duration; //-------------------------------------------
int distance; --//

int releDrift = 0; // read the analog in value:


int sensorValue = 0;
int fullStatus = 0;
int startfylling = 0; int avstand = (distance);
int tell =0; avstand = constrain(avstand, 1, 8);
avstand = map (avstand,1,8,8,1);

#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 6, 9, 10, 7);
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
void setup() digitalWrite(trigPin, LOW);
{

//Utganger og innganger// duration = pulseIn(echoPin, HIGH);


pinMode (trigPin, OUTPUT); distance = duration * 0.034 / 2;
pinMode (echoPin, INPUT);
4

pinMode (rele, OUTPUT); int vannlevel = avstand;


pinMode (normaldrift,OUTPUT);
pinMode (fyller , OUTPUT);
if (tell >=111) // 30sekunder
{ startfylling = 1; // Display
} //
//---------------------------------------------
------//
if ( startfylling == 1 && vannlevel < 6)
{
digitalWrite(rele, HIGH);
}
if (releDrift == LOW)
if ( vannlevel >= 6) {
{ lcd.clear();
digitalWrite(rele, LOW); lcd.setCursor(4, 0);
tell = 0; lcd.print("Vannstand");
startfylling = 0; lcd.setCursor(8, 1);
} lcd.print(vannlevel);
lcd.setCursor(10, 1);
lcd.print("cm");
//--------------------------------------------- delay(50);
----// lcd.clear();
lcd.setCursor(4, 0);
lcd.print("Vannstand");
lcd.setCursor(8, 1);
// LOW LEVEL lcd.print(vannlevel);
// lcd.setCursor(10, 1);
// -------------------------------------------- lcd.print("cm");
----// digitalWrite (normaldrift, HIGH);

//---------------------------------------------
5
------//
if (releDrift == HIGH)
{
lcd.clear();
Food Detector
Food Detector: (By Measuring Resistances)

Hardware components

Arduino UNO & Genuino UNO


× 1

6
Resistor 10k ohm
× 1

Adafruit Standard LCD - 16x2 White on Blue


× 1

Breadboard (generic)
× 1

Jumper wires (generic)

× 1
Schematics
Arduino Food Detect

const int frootSense = 0;


int frootResistance, high = 0, low = 1023;
int frootDetect;
#include <LiquidCrystal.h> //remove this if u don't
have LCD, anyways it wont affect.
LiquidCrystal lcd(12,11,5,4,3,2); //remove this if u don't
have LCD, anyways it wont affect.
void setup(){
Serial.begin(9600);
lcd.begin(16, 2); //remove this if u don't have
LCD, anyways it wont affect.
lcd.clear(); //remove this if u don't have
LCD, anyways it wont affect.
}
void loop()
{
lcd.clear(); //remove this if u don't have LCD,
anyways it wont affect.
lcd.setCursor(0,0); //remove this if u don't have LCD, anyways it
wont affect.
lcd.print("Food Detect:"); //remove this if u don't have LCD,
anyways it wont affect.
lcd.setCursor(0,1); //remove this if u don't have LCD,
anyways it wont affect.
frootResistance = analogRead(frootSense);
Serial.print("Resistance:");
Serial.print(frootResistance);
Serial.print("\n");
if (frootResistance>400 & frootResistance<700){
Serial.print("Cucumber \n");
lcd.print("Cucumber"); //remove this if u don't have LCD, anyways it
wont affect. 7
}
else if(frootResistance>140 & frootResistance<300){
Serial.print("Apple");
lcd.print("Apple"); //remove this if u don't have LCD, anyways it
The Traffic Light
The Traffic Light is a project that has Arduino-powered LEDs Blinking like a
traffic light.

Hardware components

Arduino UNO & Genuino UNO


Other boards can also be used, information in "About this project" × 1
under "Board Requirements"

5 mm LED: Red
× 8

5 mm LED: Yellow
× 8

5 mm LED: Green
× 8

8
Jumper wires (generic)
× 1

Breadboard (generic)
× 1

SparkFun Rectifier Diode


× 7
Recommended, jumper wires could be used

USB-A to B Cable
× 1
For controlling Arduino

Resistor 10k ohm


× 1

9
Schematics (Mini Auto V9 Image) Traffic Light Mini Auto V9 Code

int emergency = 0;
void setup() {
//sets up pins 3,4,5 as outputs
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(13, OUTPUT); //set up pin13LED as output
pinMode(2, INPUT); //set up emergency switch as
input
}

void loop() {
emergency = digitalRead(2);
if (emergency == LOW) {
// do RED for 10sec, green for 10sec, and yellow
for 3sec.
digitalWrite(13, LOW);
digitalWrite(3 , HIGH);
delay(10000);
digitalWrite(13, HIGH);
digitalWrite(3 ,LOW);
digitalWrite(5 ,HIGH);
delay(10000);
digitalWrite(5 ,LOW);
digitalWrite(4 ,HIGH);
delay(3000);
digitalWrite(4 , LOW);
}
else{
digitalWrite(3, HIGH);
digitalWrite(13, LOW);
delay(1000);
digitalWrite(3, LOW);
digitalWrite(13, HIGH);
delay(1000);
}
}
/* Notes:
Press the RESET button on your board to restart the
circuit, putting it back on RED.
To go into Emergency Mode: Hold the Emergency Button
and press RESET.
*/

10
Sensal - All Senses Alarm Clock
Wake up, get productive or sleepy with the help of all available senses only
when you need it

Hardware components

Arduino UNO & Genuino UNO


× 1

Real Time Clock (RTC)


× 1
http://playground.arduino.cc/Main/DS1302RTC

LED (generic)
× 3
3w

SparkFun FemtoBuck LED Driver


× 1
any adjustable led driver

DHT11 Temperature & Humidity Sensor (4 pins)


× 1

SparkFun Serial Enabled LCD Kit


× 1
my version- https://arduino-info.wikispaces.com/LCD-Blue-I2C

Resistor 10k ohm


× 1

Resistor 1k ohm
× 1

11
Photo resistor
× 1

9V 1A Switching Wall Power Supply


× 1
i use 12v 2a

Breadboard (generic)
× 1

Jumper wires (generic)


× 1

SparkFun Analog joystick


× 1

12
Schematics

13
Code: Arduino sketch for Sensal

// I assume you know how to connect the DS1302 #include <LiquidCrystal_I2C.h>


and LCD. #include <DS1302RTC.h>
// DS1302: RST pin -> Arduino Digital 5 #include <Time.h>
(red) #include <TimeAlarms.h>
// DAT pin -> Arduino Digital 6 #include <DHT.h>
(orange) #define LED_PIN 9
// SCLK pin -> Arduino Digital 7 #define DHTPIN 12
(yellow) #define DHTTYPE DHT11
// VCC pin -> - (my rtc works only #define LDR_PIN A0
from a built in battery, otherwise it returns #define axis_X A1 // horizontal (Х) Analog
an error, so no connection here) 1
// GND pin -> GND #define axis_Y A2 // Vertical (Y) Analog 2
// LCD: SLC -> analog A5(black) #define axis_Z 2 // Z (joystick button)
// SDA -> analog A4(white) Digital 2
// VCC -> VCC int value_X, value_Y, value_Z = 0; //
// GND -> GND variable to save joystick state
// A0 -> light control (on GND photoresistor, boolean buttonWasUp = true; // variable to
on +5v resistor (10k)) save button state
// pin 9 -> PWM light control + 1k resistor boolean ledEnabled; // Are LEDs are turned on?
// pin 12-> DHT11 (s) unsigned long previousMillis = 0;
// pin2 -> SW (joystick) unsigned long previousMillis1 = 0;
// A2 -> WRy (joystick) unsigned long previousMillis2 = 0;
// A1 -> WRx (joystick) boolean ledAlarmIsOn = false;
/* byte lastBrightnessLevel;
* byte ledBrightness = 0;
Parts: byte screenNum = 0;
- lcd i2c display byte lastScreenNum = 0;
- photoresistor to control LCD backlight byte alarmHour = 19; // set alarm hours
- joystick byte alarmMinute = 28; // set alarm minutes
- RTC module ds1302 byte cursorNum = 0;
- DHT11 temperature and humidity sensor // Initialize DHT sensor for normal 16mhz
- powerfull LEDs Arduino
- PWM adjustable DHT dht(DHTPIN, DHTTYPE);
Soon: // Init the DS1302
- speaker // Set pins: CE(rst), IO(dat),CLK
- relay to control powerful heater DS1302RTC RTC(5, 6, 7);
- fan(s) and small heater to make an // Init the LCD
aromatizer // initialize the library with the numbers of
- windows lock the interface pins (sda-a4; scl-a5)
- much-much more... LiquidCrystal_I2C lcd(0x27, 16, 2);

Functions: void setup()


- shows time, date, temperature, humidity, and {
alarm time on different screens pinMode(13, OUTPUT);
- Alarm. Only light alarm for now, sound, heat, // Serial.begin(9600);
smell will be when i get more hardware pinMode(axis_Z, INPUT_PULLUP); // joystick
- Light. Just click joystick to switch it on button
and off. analogWrite(LED_PIN, ledBrightness); // LEDs
*/ are turned off by default
// Setup LCD to 16x2 characters
//<Wire.h> Needed for LiquidCrystal_I2C.h lcd.init();//initialize screen
library
#include <Wire.h>

14
dht.begin();//initialize dht11 sensor if ( ledBrightness == endLed ||
setSyncProvider(RTC.get); // the ledBrightness < lastBrightnessLevel) {
function to get the time from the RTC if(ledBrightness != startLed && blink ==
// Alarm daily true && (unsigned int)(millis() -
Alarm.alarmRepeat(alarmHour, alarmMinute , 0, previousMillis) >= interval )
MorningAlarm); // alarm time {
} previousMillis = millis();
lastBrightnessLevel = ledBrightness;
ledBrightness--;
void loop() analogWrite(LED_PIN, ledBrightness);
{ }
}
// turn LEDs on if alarm is on. (pause in // was brightness increasing?
milliseconds between brightness levels, else if (ledBrightness == startLed ||
//starting level of brightness , final level ledBrightness >= lastBrightnessLevel) {
of brightness, if (ledAlarmIsOn == true && ledBrightness
//should it blink in a given range) < endLed && ((unsigned int)(millis() -
AlarmLed(3000, 0, 40, false); previousMillis) >= interval) ){
AlarmLed(1500, 40, 70, false); previousMillis = millis();
AlarmLed(100, 60, 220, false); lastBrightnessLevel = ledBrightness;
AlarmLed(50, 60, 220, true); ledBrightness++;
readJoystick(); //read joystick movements analogWrite(LED_PIN, ledBrightness);
click (); // read joystick button state }
joystick(); // //control LED brightness with }
joystick }
screenBacklight(); // screen autobrightness void click () {
screens(screenNumX()); // showing different value_Z = digitalRead(axis_Z); // read
screens joystick butoon state
Alarm.delay (1); // Wait small time before // is button pressed now?
repeating, needed for aralm boolean buttonIsUp = digitalRead(axis_Z);
} // if was up (&&) and not up now»...
void print2digits(int number) { if (buttonWasUp && !buttonIsUp) {
if (number >= 0 && number < 10) { // ...it may be click or fault signal, so
lcd.write('_'); we wait a little
} delay(5);
lcd.print(number); // ... and read signal again
} buttonIsUp = digitalRead(axis_Z);
if (!buttonIsUp) { // if it is still
// this method is needed for alarm to work presed
void MorningAlarm() { // ...it is a click. Revert LED state
ledAlarmIsOn = true; ledEnabled = !ledEnabled;
} if (ledEnabled ) {
// control LED. (on-off-blinking in given range ledBrightness = 110;
of brightness) (pause in milliseconds between analogWrite(LED_PIN, ledBrightness);
brightness levels,
//starting level of brightness , final level of }
brightness, else if (ledAlarmIsOn) {
//should it blink in a given range) ledAlarmIsOn = false;
ledBrightness = 0;
void AlarmLed(unsigned int interval, int analogWrite(LED_PIN, ledBrightness);
startLed, int endLed, boolean blink) { }
// was brightness decreasing?

15
else { }
ledBrightness = 0; }
analogWrite(LED_PIN, ledBrightness); }
}
} // change screen number
} byte screenNumX() {
buttonWasUp = buttonIsUp; // remember last
state of the button lastScreenNum = screenNum;
} if (millis() >= (previousMillis1 + 500)) {
// comparing current time with previous time
plus 0.5 seconds
void screenBacklight() { previousMillis1 = millis();
// screen autobrightness if (value_X >= 0 && value_X < 490 )
if ( analogRead(LDR_PIN) >= 890 && screenNum++;
ledAlarmIsOn == false) { if (value_X > 510 && value_X > 980 )
screenNum++;
lcd.noBacklight(); }
} if (screenNum > 1) screenNum = 0;
else { return screenNum;
lcd.backlight(); }
}
} // change screen depending on screen number
void screens(byte x) {
//control LED brightness with joystick if (lastScreenNum != screenNum)
void joystick() { lcd.clear(); // if screen is changing, clear it
before change
if (ledEnabled) if (screenNum == 0 ) {

{ // print current ledbrightness


lcd.setCursor(13, 1);
if (millis() >= (previousMillis + 200)) { lcd.print(ledBrightness);
// comparing current time with previous time lcd.print(F(" "));
plus 0.2 seconds
int h = dht.readHumidity(); // Read
previousMillis = millis(); Humidity
int t = dht.readTemperature(); // Read
else if (value_Y > 50 && value_Y < 485 && temperature as Celsius
screenNum == 1 ) cursorNum--; // print humidity
lcd.setCursor(9, 0);
if (value_Y > 495 && value_Y < 900 && lcd.print('h');
ledBrightness < 160) ledBrightness++; lcd.setCursor(10, 0);
lcd.print(h);
else if (value_Y > 495 && value_Y < 900 // print temp
&& screenNum == 1 ) cursorNum++; lcd.setCursor(13, 0);
lcd.print('t');
if (value_Y > 980 && ledBrightness < 159) lcd.setCursor(14, 0);
ledBrightness += 2; lcd.print(t);

else if (value_Y > 980 && screenNum == 1 ) static int sday = 0;// Saved day number for
cursorNum ++; change check
analogWrite(LED_PIN, ledBrightness);

16
void readJoystick() {
// Display time centered on the upper line value_X = analogRead(axis_X); // read
lcd.setCursor(0, 0); horizontal (Х) joystick
print2digits(hour()); value_Y = analogRead(axis_Y); // read
lcd.print(' '); vertical (y) joystick
print2digits(minute()); }
lcd.print(' ');
print2digits(second());

// Update in 00:00:00 hour only


if (sday != day() || lastScreenNum != 0 ) {
// Display abbreviated Day-of-Week in the
lower left corner
lcd.setCursor(0, 1);
lcd.print(dayShortStr(weekday()));
// Display date in the lower right corner
lcd.setCursor(4, 1);
lcd.print(' ');
print2digits(day());
lcd.print('/');
print2digits(month());
// lcd.print("/");
// lcd.print(year());
}
// Warning!
if (timeStatus() != timeSet) {
lcd.setCursor(0, 1);
lcd.print(F("RTC ERROR: SYNC!"));
}
// Save day number
sday = day();
}

else if (screenNum == 1 && lastScreenNum !=


screenNum) {

if (cursorNum == 0 || cursorNum == 1) {

if (millis() >= (previousMillis2 + 100))


{ // comparing current time with previous
time plus 0.1 seconds
previousMillis2 = millis();

lcd.setCursor(0, 0);
}
lcd.print(alarmHour);
lcd.print(' ');
lcd.print(alarmMinute);
}
}
}

17
Build a Simple Cocktail Drinkbot with Arduino (By Ted Kinsman)
Big parties need a conversation piece, and what’s better than a drink-making
robot? Not only is it a good conversation starter, it also frees up the party host who would normally
be the bartender. It turned out that the drink robot was a really good idea.
The robot is really an Arduino microprocessor (Uno version) that controls a number of pumps. A
simple program allows the pumps to turn on for the required time to make a mixed drink. The idea
here, is to get building and understand the basic concepts to make your own drink robot.

PARTS
 --MAI TAI PARTS--
 Rum, 30 ml.
 Curacao (Orange), 12 ml.
 Orgeat (Almond Syrup), 5 ml.
 Grenadine Syrup, 6 ml.
 Pineapple Juice + Lime, 120 ml. 10 squeezed limes added to 1 gallon of pineapple juice
ROBOT PARTS
 Arduino Uno
 Small Motors (shouldn't draw more than 120 mA when pumping)

18
 Aquarium Peristaltic Pumps (2)
 Submersible 12-volt Pump
 Elegoo Resister Block
 Doorbell Switch

Making the Bot


The first step was to calibrate the pumps and see how fast they pumped
liquid at 12 VDC. The motors I used were found on the Internet and cost about $5 each. Since they
each draw 120 mA when pumping, I needed to use a power supply that could supply several amps to
make the drink. The second design parameter was to determine how fast a drink could be reasonably
made. I decided that 35 seconds was a reasonable time to wait for a drink.
Peristaltic pumps are used to deliver specific amounts of liquids and use a rolling ball mechanism in a
section of flexible tube. These pumps are common in the food and medical industries. The smaller
versions used in this project are common in the aquarium industry where they deliver chemicals to
fish tanks. The peristaltic pumps I used are able to pump 30 ml in 32 seconds.

The peristaltic pumps from the front.

Back of the peristaltic pumps. Note the


current limiting resisters on the blue LEDs
placed above the pump motors. From the
front, these LEDs strobe in sequence when
the machine is waiting to make a drink.
When activated, the blue LEDs are used to
show which pump is working.

19
The resistor block is manufactured by Elegoo and has 8 Channels. It is controlled by 5-volts from the
Arduino Uno. Note: to turn a relay on with this board, a control pin has to be written to a LOW value.

The computer code presented below in this article can easily be modified to deliver any drink in any
strength desired. It should be noted that the device is not limited to only one drink. The design can
be modified to make numerous drinks each selected by a push button.

20
Code for Build a Simple Cocktail Drinkbot with Arduino

/*This program is DrinkRobotMaiTie and makes th #define LED11 11 // LED above pump4 connected t
e spectacular o pin 11

* drink Margot's Mai Tai


#define PineLime 5 //pump5 connected to pineapp
le and lime juice
* and was written by

#define LED12 12 // LED above pump5 connected t


*Ted Kinsman Rochester Institute of Technology o pin 12

*March 2017 emkpph@rit.edu

#define doorbell 13 // trigger switch uses a do


*12 v DC motors pump 1 oz of liquor in 32 sec. orbell

*/ #define pump6 6 // pump 6 big submersed pump

#define Rum 1 // (pump1)12VDC motor to pump rum


on pin 1 int strobe=100; // this controls how fast the L
EDs will blink in line

#define LED8 8 // (pump1)LED to tell rum is pum


ping int sensorPin = A0; // analog read : used to te
ll if doorbell switch is pushed

#define Curacao 2 // (pump2) Curacao (orange) l int sensorValue = 0; //value written to when a
iquor connected to pin 2 nalog value is read from doorbell

#define LED9 9 // (pump2)LED to tell Curacao (o


range) liquor is pumping void setup()

#define Orgeat 3 // (pump3) on pin 3 {

#define LED10 10 // LED above pump 3 connected pinMode(Rum, OUTPUT);


to pin 10
pinMode(LED8, OUTPUT);

#define Grenedine 4 // pump4 on pin 4


pinMode(Curacao, OUTPUT);

21
pinMode(LED9, OUTPUT); digitalWrite (Grenedine, HIGH);//pump 5 off

pinMode(Orgeat, OUTPUT); digitalWrite (pump6, HIGH);//pump 6 off

pinMode(LED10, OUTPUT); delay(1000); // let relays settle down before r


unning the first time.

pinMode(Grenedine, OUTPUT);
}

pinMode(LED11, OUTPUT);
void loop() //this part of the code loops and
loops forever
pinMode(LED12, OUTPUT);

{
pinMode(doorbell, INPUT);

sensorValue = analogRead(sensorPin);
pinMode(pump6, OUTPUT);

//this part makes the LEDs strobe to make the r


digitalWrite (LED8, LOW); //led 1 on obot look cool

digitalWrite (Rum, HIGH); //pump 1 off //this stops when the start button is pressed

digitalWrite (LED9, LOW); //if bottom is pressed the LEDs show which moto
r is running
digitalWrite (LED8, HIGH); //turns on LED on pi
digitalWrite (Curacao, HIGH); //pump 2 off n 8
digitalWrite (LED10, LOW);
delay(strobe); // controls how fast the
LEDs flash
digitalWrite (Orgeat, HIGH); //pump 3 off

digitalWrite (LED8, LOW); //turns off LED on pi


digitalWrite (LED11, LOW); //pump 4 off n 8

digitalWrite (PineLime, HIGH); //pump 4 off delay(strobe);


digitalWrite (LED9, HIGH); //turns on LED on pi
digitalWrite (LED11, LOW); n 9

22
delay(strobe); sensorValue = analogRead(sensorPin);

digitalWrite (LED9, LOW); //turns off LED on pi if(sensorValue < 300){


n 9

digitalWrite (LED8, HIGH); //led 1 on


delay(strobe);

digitalWrite (Rum, LOW); //pump 1 on


digitalWrite (LED10, HIGH); //turns on LED on p
in 10
digitalWrite (LED9, HIGH);

delay(strobe);
digitalWrite (Curacao, LOW); //pump 2 on

digitalWrite (LED10, LOW); //turns off LED on p


in 10 digitalWrite (LED10, HIGH);

delay(strobe); digitalWrite (Orgeat, LOW); //pump 3 on

digitalWrite (LED11, HIGH); //turns on LED on p digitalWrite (LED11, HIGH);


in 11

digitalWrite (Grenedine, LOW);//pump 4 on


delay(strobe);

delay(8000); // waits 8 sec to pump 1/4 o


digitalWrite (LED11, LOW); //turns off LED on p z of liquid
in 11

digitalWrite (LED10, LOW); // turns off Orgeat


delay(strobe); LED P3
digitalWrite (Orgeat, HIGH); // turns off Org
digitalWrite (LED12, HIGH); //turns on LED on p eat pump P3
in 12

digitalWrite (LED11, LOW); //led for pump 5 o


delay(strobe); ff

digitalWrite (LED12, LOW); //turns off LED on p digitalWrite (Grenedine, HIGH); //turns off pim
in 12 p 4

delay(strobe);

23
delay(8000); // waits 8 sec to pump 1/4 oz
of liquid

digitalWrite (Curacao, HIGH); // turns off Cu


racao pump 2

digitalWrite (LED9, LOW); // turns off Curacao


LED 2

// at this point the Curacao has been on for 16


sec and has pumped 1/2 oz

delay(16000); // waits 8 sec to pump 1/4 oz o


f liquid

digitalWrite (LED8, LOW); //turns off pump 1 LE


D

digitalWrite (Rum, HIGH); //turns off pump 1


(RUM)

digitalWrite (pump6, LOW); //turn on pineappl


e pump (pump6)
//digitalWrite (PineLime, LOW); //low turns on
relays to turn on pump

delay(2500); //delay 4 seconds to pump pineappl


e juice

digitalWrite (pump6, HIGH); // turn off pin


eapple pump (pump6)

//digitalWrite (PineLime, HIGH); // turns off r


elays to pineapple juice

24
Arduino Temperature Control
This project is about control of temperature in values of 23 and 25 grades
and control for hysteresis using DHT22 and Arduino 101
The project does a temperature control, we model the following situation:
The system starts and shows the temperature, if the temperature reaches 25 degrees, then the
green led is activated and the room starts to cool until the temperature drops to 23 degrees, the
air conditioner turns off (red led) until the temperature rises again

25
COMPONENTS AND SUPPLIES
Arduino 101 & Genuino 101

× 1

DHT22 Temperature Sensor

× 1

Jumper wires (generic)

× 1

LED (generic)

× 2

Resistor 10k ohm

× 1

Resistor 330 ohm

× 2

DFRobot LCD button Shield


× 1

Breadboard (generic)

× 1

26
27
CODE

/*By Alexis Santiago Allende */ > interval) //Comparison between the


/*Last update: 12/03/2017*/ elapsed time and the time in which the
#include "DHT.h"//DHT sensor Library action is to be executed
#include <LiquidCrystal.h>//LCD Library {
#define DHTPIN 12 //Define sensor previousMillis = currentMillis;
pin(pin 12) //"Last time is now"
#define DHTTYPE DHT22 //What sensor use
h = dht.readHumidity();//humidity
DHT dht(DHTPIN, DHTTYPE);//Create sensor value
object t =
LiquidCrystal lcd(8, 9, 4, 5, 6, dht.readTemperature();//temperature
7);//Create lcd object using this pins value centigrades if you want farenheit
8,9,4,6,7 change to
//t = dht.readTemperature(true);
boolean a=LOW,b=HIGH; //Below is for print data sensors
float h=0,t=0; in lcd
const int ledPin = 3; //LED pins for lcd.setCursor(10,0);
temperature control lcd.print(t);
const int ledPin2 = 2; lcd.setCursor(10,1);
long previousMillis = 0; lcd.print(h);
long interval = 2000; //Read sensor each
2 seconds if(t>=25 && a==LOW)//if temperature
void setup() { above of 25 degrees
lcd.begin(16, 2); //Start {
lcd digitalWrite(ledPin,HIGH);//Active
lcd.setCursor(0,0); //Set in air conditioner
position 0,0 digitalWrite(ledPin2,LOW);
// set the digital pin as output: a=HIGH;
pinMode(ledPin, OUTPUT);//Change to b=LOW;
output my pins
pinMode(ledPin2, OUTPUT); }
dht.begin();//Start DHT22 sensor else if(t<=23&&b==LOW)//if
digitalWrite(ledPin2,LOW);//Turn off LED temperature is under 23 degrees
digitalWrite(ledPin,LOW);//Turn off LED {
lcd.print("Tempera:");// print in lcd digitalWrite(ledPin2,HIGH);
this word digitalWrite(ledPin,LOW);//Turn
lcd.setCursor(0,1);//Change cursor off air conditioner
position a=LOW;
lcd.print("Humedad:");// print in lcd b=HIGH;
this word }
}
void loop() }
{ }
unsigned long currentMillis =
millis();//time elapsed 28
if(currentMillis - previousMillis
SCHEMATICS

29
Eye Motion Tracking Using Infrared Sensor
Use an infrared sensor to sense eye movements and control an LED.

COMPONENTS AND SUPPLIES


SparkFun Arduino Pro Mini 328 - 5V/16MHz

× 1

Adafruit LiIon/LiPoly Backpack Add-On for Pro


Trinket/ItsyBitsy × 1

NeoPixel strip

× 1

QTR-1A Reflectance Sensor


× 1

3.7 V LiPo Battery


× 1

NeoPixel LED Eye Ball


NeoPixel LED tape is used. LED is 68 unit. LED is fixed to the bowl with double-sided tape and
wired in the following order.

30
Eye Motion Tracking

Schematics

31
Sensor
I used two sensors QTR - 1A for eye tracking. QTR - 1A are placed on a plastic sheet at a
distance of about the width of the eye.

32
The sensor part and the microcontroller part were fixed to the eyeglasses with a clip
respectively.

Arduino Code
When the iris approaches one sensor, the reflected light decreases and the sensor value
increases. Conversely, when the iris moves away, the reflected light increases and the sensor
value of the photo reflector decreases.
The right and left movement of the pupil of the LED eyeball senses the increase and decrease of
one sensor value and controls it.
When blinking, both sensor values decrease, so if the two sensor values decrease
simultaneously, the eyelids of the LED eyeball will go down.

#include <QTRSensors.h>
#include <Adafruit_NeoPixel.h>
#define NUM_SENSORS 2 // number of sensors used
#define NUM_SAMPLES_PER_SENSOR 10 // averaging
#define EMITTER_PIN QTR_NO_EMITTER_PIN
33
int iniSensorValL, sensorValL;
int iniSensorValR, sensorValR;
#define PIN A3
Adafruit_NeoPixel led = Adafruit_NeoPixel(68, PIN, NEO_GRB + NEO_KHZ800);
int blackNum = 24;
int pupilNum = 12;
uint32_t color;
int brightness = 40;
byte eyeColor;
int LR =7;
boolean lid = false;
int cnt = 0;
//Black eye L&R animation
int blackLED[15][24] = {{12,32,35,55,68,68,68,68,68,68,68,68,68,68,68,68,68,68,68,68,6
8,68,68,68},
{12,13,31,36,54,55,68,68,68,68,68,68,68,68,68,68,68,68,68,68,68
,68,68,68},
{11,13,14,30,37,53,54,56,68,68,68,68,68,68,68,68,68,68,68,68,68
,68,68,68},
{10,11,14,15,29,38,52,53,56,57,68,68,68,68,68,68,68,68,68,68,68
,68,68,68},
{ 9,10,11,12,15,16,28,33,34,39,51,52,55,56,57,58,68,68,68,68,68
,68,68,68},
{ 0, 8, 9,10,11,12,13,16,17,27,32,35,40,50,51,54,55,56,57,58,59
,67,68,68},
{ 0, 1, 7, 8, 9,10,13,14,17,18,26,31,36,41,49,50,53,54,57,58,59
,60,66,67},
{ 1, 2, 6, 7, 8, 9,14,15,18,19,25,30,37,42,48,49,52,53,58,59,60
,61,65,66},
{ 2, 3, 5, 6, 7, 8,15,16,19,20,24,29,38,43,47,48,51,52,59,60,61
,62,64,65},
{ 3, 4, 5, 6, 7,16,17,20,21,23,28,39,44,46,47,50,51,60,61,62,63
,64,68,68},
{ 4, 5, 6,17,18,21,22,27,40,45,46,49,50,61,62,63,68,68,68,68,68
,68,68,68},
{ 4, 5,18,19,26,41,48,49,62,68,68,68,68,68,68,68,68,68,68,68,68
,68,68,68},
{ 4,19,20,25,42,47,48,63,68,68,68,68,68,68,68,68,68,68,68,68,68
,68,68,68},
{20,21,24,43,46,47,68,68,68,68,68,68,68,68,68,68,68,68,68,68,68
,68,68,68},
{21,23,44,46,68,68,68,68,68,68,68,68,68,68,68,68,68,68,68,68,68
,68,68,68}};
//pupil L&R animation
int pupilLED[15][12] = {{33,34,68,68,68,68,68,68,68,68,68,68},
{32,33,34,35,68,68,68,68,68,68,68,68},
{12,31,32,33,34,35,36,55,68,68,68,68},
{12,13,30,31,32,33,34,35,36,37,54,55},
{13,14,29,30,31,32,35,36,37,38,53,54},
{14,15,28,29,30,31,36,37,38,39,52,53},
{15,16,27,28,29,30,37,38,39,40,51,52},
{16,17,26,27,28,29,38,39,40,41,50,51},
{17,18,25,26,27,28,39,40,41,42,49,50},
{18,19,24,25,26,27,40,41,42,43,48,49},
{19,20,23,24,25,26,41,42,43,44,47,48},
{20,21,22,23,24,25,42,43,44,45,46,47},
{21,22,23,24,43,44,45,46,68,68,68,68},
{22,23,44,45,68,68,68,68,68,68,68,68},
{22,45,68,68,68,68,68,68,68,68,68,68}};
//Blink animation
int eyelid = 0;
34
int eyelidNum[8] = {0,4,8,16,24,34,44,56};
int eyelidLED[56] = {64,65,66,67,58,59,60,61,56,57,62,63,49,50,51,52,47,48,53,54,38,39
,40,41,46,55,36,37,42,43,26,27,28,29,35,44,24,25,30,31,15,16,17,18,34,45,23,32,13,14,1
9,20,6,7,8,9};
QTRSensorsAnalog qtra((unsigned char[]) {0, 1}, NUM_SENSORS, NUM_SAMPLES_PER_SENSOR, E
MITTER_PIN);
unsigned int sensorValues[NUM_SENSORS];
void blink(int eyelid, int LR) {
if (eyelid != 8){
//Pewter
for(uint16_t i=0; i<led.numPixels(); i++) {
led.setPixelColor(i, led.Color(66, 66, 66));
}
//Black eye
for(uint16_t i=0; i<blackNum; i++) {
led.setPixelColor(blackLED[LR][i], color);
}
//pupil
for(uint16_t i=0; i<pupilNum; i++) {
led.setPixelColor(pupilLED[LR][i], led.Color(0, 0, 66));
}
//eyelid
for(int i=0; i < eyelidNum[eyelid]; i++) {
led.setPixelColor(eyelidLED[i], 0);
}
} else if (eyelid == 8){
led.clear();
}
led.show();
}
void setup() {
Serial.begin(115200);
led.begin();
led.setBrightness(brightness); // Initial Brightness 40
led.show(); // Initialize all pixels to 'off'
color = led.Color(0, 177, 55); //pupil color
delay(100);
qtra.read(sensorValues);
iniSensorValL = sensorValues[0];
iniSensorValR = sensorValues[1];
blink(eyelid, LR);
}
void loop() {
//QTR - 1A sensor value
qtra.read(sensorValues);
sensorValL = sensorValues[0];
sensorValR = sensorValues[1];
double rasioL = (double)sensorValL / iniSensorValL;
double rasioR = (double)sensorValR / iniSensorValR;
Serial.print(rasioL);
Serial.print(" ");
Serial.println(rasioR);
if(rasioL > 0.985 && rasioR < 0.985){ //right
for(int i = LR; i < 12; i++){
blink(0, i);
delay(40);
LR = i;
}
}else if(rasioL < 0.985 && rasioR > 0.985){ //left
for(int i=LR; i>2; i--){
blink(0, i);
35
delay(40);
LR = i;
}
}else if(lid == false && rasioL < 0.96 && rasioR < 0.96){ //Blinking close
for(int i = 1; i < 9; i++){
blink(i, LR);
delay(40);
lid = true;
}
}else if(lid == true && rasioL > 0.96 && rasioR > 0.96){ //Blinking open
for(int i = 8; i > 0; i--){
blink(i, LR);
delay(40);
lid = false;
}
}else if(lid == false && rasioL > 0.96 && rasioR > 0.96) { //normal
//cnt++;
//eyelid = 0;
if(LR <= 7){
for(int i=LR; i<=7; i++){
blink(0, i);
delay(40);
LR = i;
}
}else {
for(int i=LR; i>=7; i--){
blink(0, i);
delay(40);
LR = i;
}
}
Serial.println("通常時");
}
//Initial value refresh
if (cnt > 10){
iniSensorValL = sensorValL;
iniSensorValR = sensorValR;
cnt = 0;
}
}

Arduino - Have Fun with Color Sensor © GPL3+


This project shows how to change color of Minion using Arduino, PHPoC WiFi Shield and color sensor.

36
COMPONENTS AND SUPPLIES
Arduino UNO & Genuino UNO

× 1

PHPoC WiFi Shield for Arduino

We can use PHPoC Shield instead


× 1

MikroElektronika ISL29125 RGB Color Sensor

We can use the same sensor from × 1


https://www.sparkfun.com/products/12829

Wiring
 Stack PHPoC WiFi shield on Arduino.
 Connect pin GND, 3.3V, pin SCL and SDA of color sensor to GND, 3.3V, A4 and A5 of Arduino,
respectively. (see schematics section)
Data Flow
Arduino ---> PHPoC WiFi Shield ---> Web browser
Arduino reads RGB color values from sensor and send the values to PHPoC WiFi Shield. When
receiving the color values, PHPoC WiFi Shield send it to Web browser via websocket. Web
browser changes background color to the received color.
Since background image is png image, some parts of image is transparent. Therefore, we will
see the background color in transparent part of background image. In the demonstration, body
of Minion is transparent. When background color is changed, we will see the color of Minion is
changed.
Note that: PHPoC shield has a built-in program to pass data from Arduino to web browser.
Therefore, we don't need to care about it.

What We Need to Do
 Set WiFi information for PHPoC shield (SSID and password)
 Upload new UI to PHPoC shield

37
 Write Arduino code
Setting WiFi Information for PHPoC Shield
See this instruction.
Upload new Web UI to PHPoC Shield
 Download PHPoC source code remote_color.php (on code section) and background.png file.

background.png

 Upload them to PHPoC shield using PHPoC debugger according to this instruction.
Write Arduino Code
 Install three following libraries: PHPoC Library for Arduino, SparkFun ISL29125(see instruction).
 Upload Arduino code (on code section) to Arduino.
Testing
 Click serial button on Arduino IDE to see the IP address.
 Open web browser, type http:// replace_ip_address /remote_color.php
 Click connect button and test it.

CODE

#include <Wire.h> if (client) {


#include "SparkFunISL29125.h" // Read sensor values (16 bit
#include "SPI.h" integers) 38
#include "Phpoc.h" unsigned int red =
RGB_sensor.readRed();
// Declare sensor object unsigned int green =
SCHEMATICS

39
40
Arduino Security and Alarm System Project

If you ever thought of making your own security system then this project is a great starting
point. Here we will utilize an ultrasonic sensor for detecting movement.

If a human or object passes in front of the sensor, the alarm will be activated. For deactivating the
alarm you will have to enter a password using a keypad.

Required Components

Now let’s see the required components for this project. Obviously, we need an Arduino board, an
ultrasonic sensor, an LCD display, a buzzer and a 4×4 keypad.

41
Circuit Schematics

So for the buzzer we need just a single pin but one with PWM support. The 4×4 keypad has 8 pins, 4
of them are for the rows and 4 of them for the columns of the keypad. Each button is actually a push
button switch which makes a short between one row and column when pressed.

So, for example, if we set the row 1 line low, and all column lines high, when we will press, for
example, the button 3, due to the short between the two lines, the column 3 line will drop to low so in
such a case we can register that the button 3 has been pressed.

As for the other two components on this project, the ultrasonic sensor and the LCD display, you can
check my previous detailed tutorials on how to connect and use them.

42
Arduino Alarm System Source Code

1. if (!alarmActivated) {
1. #include <LiquidCrystal.h> // includes the LiquidCrystal 2. if (screenOffMsg == 0 ){
Library 3. lcd.clear();
2. #include <Keypad.h> 4. lcd.setCursor(0,0);
3. 5. lcd.print("A - Activate");
4. #define buzzer 8 6. lcd.setCursor(0,1);
5. #define trigPin 9 7. lcd.print("B - Change Pass");
6. #define echoPin 10 8. screenOffMsg = 1;
7. 9. }
8. long duration; 10. keypressed = myKeypad.getKey();
9. int distance, initialDistance, currentDistance, i; 11. if (keypressed =='A'){ //If A is pressed, activate the alarm
10. int screenOffMsg =0; 12. tone(buzzer, 1000, 200);
11. String password="1234"; 13. activateAlarm = true;
12. String tempPassword; 14. }
13. boolean activated = false; // State of the alarm
14. boolean isActivated; 15. if (activateAlarm) {
15. boolean activateAlarm = false; 16. lcd.clear();
16. boolean alarmActivated = false; 17. lcd.setCursor(0,0);
17. boolean enteredPassword; // State of the entered password 18. lcd.print("Alarm will be");
to stop the alarm 19. lcd.setCursor(0,1);
18. boolean passChangeMode = false; 20. lcd.print("activated in");
19. boolean passChanged = false; 21.
20. 22. int countdown = 9; // 9 seconds count down before
21. const byte ROWS = 4; //four rows activating the alarm
22. const byte COLS = 4; //four columns 23. while (countdown != 0) {
23. char keypressed; 24. lcd.setCursor(13,1);
24. //define the cymbols on the buttons of the keypads 25. lcd.print(countdown);
25. char keyMap[ROWS][COLS] = { 26. countdown--;
26. {'1','2','3','A'}, 27. tone(buzzer, 700, 100);
27. {'4','5','6','B'}, 28. delay(1000);
28. {'7','8','9','C'}, 29. }
29. {'*','0','#','D'} 30. lcd.clear();
30. }; 31. lcd.setCursor(0,0);
31. byte rowPins[ROWS] = {14, 15, 16, 17}; //Row pinouts of 32. lcd.print("Alarm Activated!");
the keypad 33. initialDistance = getDistance();
32. byte colPins[COLS] = {18, 19, 20, 21}; //Column pinouts of 34. activateAlarm = false;
the keypad 35. alarmActivated = true;
33. 36. }
34. Keypad myKeypad = Keypad( makeKeymap(keyMap),
37. }
rowPins, colPins, ROWS, COLS);
38. }
35. LiquidCrystal lcd(1, 2, 4, 5, 6, 7); // Creates an LC object.
39. if (k > 9 || keypressed == '#') {
Parameters: (rs, enable, d4, d5, d6, d7)
40. tempPassword = "";
36. void setup() {
41. k=5;
37. lcd.begin(16,2);
42. lcd.clear();
38. pinMode(buzzer, OUTPUT); // Set buzzer as an output
43. lcd.setCursor(0,0);
39. pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output
44. lcd.print(" *** ALARM *** ");
40. pinMode(echoPin, INPUT); // Sets the echoPin as an Input
45.
41. }

42.

43
1. lcd.setCursor(0,1); 1. lcd.clear();
2. lcd.print("Pass>"); 2. lcd.setCursor(0,0);
3. } 3. lcd.print("Current Password");
4. if ( keypressed == '*') { 4. lcd.setCursor(0,1);
5. if ( tempPassword == password ) { 5. lcd.print(">");
6. activated = false; 6. }
7. alarmActivated = false; 7. if ( keypressed == '*') {
8. noTone(buzzer); 8. i=1;
9. screenOffMsg = 0; 9. tone(buzzer, 2000, 100);
10. } 10. if (password == tempPassword) {
11. else if (tempPassword != password) { 11. tempPassword="";
12. lcd.setCursor(0,1); 12. lcd.clear();
13. lcd.print("Wrong! Try Again"); 13. lcd.setCursor(0,0);
14. delay(2000); 14. lcd.print("Set New Password");
15. lcd.clear(); 15. lcd.setCursor(0,1);
16. lcd.setCursor(0,0); 16. lcd.print(">");
17. lcd.print(" *** ALARM *** "); 17. while(passChangeMode) {
18. lcd.setCursor(0,1); 18. keypressed = myKeypad.getKey();
19. lcd.print("Pass>"); 19. if (keypressed != NO_KEY){
20. } 20. if (keypressed == '0' || keypressed == '1' || keypressed == '2'
21. } || keypressed == '3' ||
22. } 21. keypressed == '4' || keypressed == '5' || keypressed == '6' ||
23. } keypressed == '7' ||
22. keypressed == '8' || keypressed == '9' ) {
24. else if (keypressed =='B') { 23. tempPassword += keypressed;
25. lcd.clear(); 24. lcd.setCursor(i,1);
26. int i=1; 25. lcd.print("*");
27. tone(buzzer, 2000, 100); 26. i++;
28. tempPassword = ""; 27. tone(buzzer, 2000, 100);
29. lcd.setCursor(0,0); 28. }
30. lcd.print("Current Password"); 29. }
31. lcd.setCursor(0,1); 30. if (i > 5 || keypressed == '#') {
32. lcd.print(">"); 31. tempPassword = "";
33. passChangeMode = true; 32. i=1;
34. passChanged = true; 33. tone(buzzer, 2000, 100);
35. while(passChanged) { 34. lcd.clear();
36. keypressed = myKeypad.getKey(); 35. lcd.setCursor(0,0);
37. if (keypressed != NO_KEY){ 36. lcd.print("Set New Password");
38. if (keypressed == '0' || keypressed == '1' || keypressed == 37. lcd.setCursor(0,1);
'2' || keypressed == '3' || 38. lcd.print(">");
39. keypressed == '4' || keypressed == '5' || keypressed == '6' 39. }
|| keypressed == '7' || 40. if ( keypressed == '*') {
40. keypressed == '8' || keypressed == '9' ) { 41. i=1;
41. tempPassword += keypressed; 42. tone(buzzer, 2000, 100);
42. lcd.setCursor(i,1); 43. password = tempPassword;
43. lcd.print("*"); 44. passChangeMode = false;
44. i++; 45. passChanged = false;
45. tone(buzzer, 2000, 100); 46. screenOffMsg = 0;
46. } 47. }
47. } 48. }
48. if (i > 5 || keypressed == '#') { 49. }
49. tempPassword = ""; 50. }
50. i=1; 51. }
51. 52. }

44

You might also like