Ardduino Project
Ardduino Project
char temp;
void setup()
{
Serial.begin(9600); // Baud rate of 9600bps
pinMode(12,OUTPUT); //pin 12 declared as output
pinMode(13,OUTPUT); // pin 13 declared as output
delay(10); // delay of 10ms
}
void loop()
{
while(!Serial.available()); // stay on this line if no data is received serially
if(Serial.available()>0) // check if some data is available to be read
{
temp=Serial.read(); // read the incoming serial data byte and store in temp
if(temp=='1')
{
digitalWrite(13,HIGH);
digitalWrite(12,LOW);
}
if(temp=='2')
{
digitalWrite(13,LOW);
digitalWrite(12,HIGH);
}
if(temp=='3')
{
digitalWrite(13,HIGH);
digitalWrite(12,HIGH);
}
if(temp=='4')
{
digitalWrite(13,LOW);
digitalWrite(12,LOW);
}
}
Voting Machine Using Arduino
void setup()
{
cflag=EEPROM.read(0); //read the status of cflag from memory
v1=EEPROM.read(1);// v1 stores the vote count of party A
v2=EEPROM.read(2); // v2 stores thevote count of party B
v3=EEPROM.read(3); // v3 stores the vote count of party C
pinMode(a,INPUT); // declaration of buttons as input
pinMode(b,INPUT);
pinMode(c,INPUT);
pinMode(total,INPUT);
pinMode(closed,INPUT);
pinMode(result,INPUT);
pinMode(clearbutton,INPUT);
digitalWrite(a,HIGH); //default status of buttons when not pressed is high
digitalWrite(b,HIGH);
digitalWrite(c,HIGH);
digitalWrite(total,HIGH);
digitalWrite(closed,HIGH);
digitalWrite(result,HIGH);
digitalWrite(clearbutton,HIGH);
lcd.begin(16,2);
if(cflag==0)
{
lcd.print("Press button");
lcd.setCursor(0,1);
lcd.print("to vote...");
delay(1000);
}
if(cflag==1)
{
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Voting Closed");
lcd.setCursor(0,1);
v=v1+v2+v3;
lcd.print("Total Votes:");
lcd.print(v);
}
}
void rpt()
{
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Press button");
lcd.setCursor(0,1);
lcd.print("to vote...");
}
else
{
if(v1>v3)
{
lcd.clear();
lcd.setCursor(0,0);
lcd.print("B wins by");
lcd.setCursor(0,1);
lcd.print(v2-v1);
lcd.print(" votes");
}
else
{
if(v2>v3)
{
lcd.clear();
lcd.setCursor(0,0);
lcd.print("B wins by");
lcd.setCursor(0,1);
lcd.print(v2-v3);
lcd.print(" votes");
}
if(v2<v3)
{
lcd.clear();
lcd.setCursor(0,0);
lcd.print("C wins by");
lcd.setCursor(0,1);
lcd.print(v3-v2);
lcd.print(" votes");
}
}
}
}
void loop()
{
if(digitalRead(a)==LOW && cflag==0) // if party A button is pressed
{
v1=v1+1;
EEPROM.write(1,v1);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("vote received...");
delay(1500);
rpt();
}
// if result button is pressed and before that close button was pressed
if(digitalRead(result)==LOW && cflag==1)
{
lcd.clear();
lcd.setCursor(0,0);
lcd.print("A:");
lcd.print(v1);
lcd.setCursor(7,0);
lcd.print("B:");
lcd.print(v2);
lcd.setCursor(0,1);
lcd.print("C:");
lcd.print(v3);
delay(1500);
if(v1>v2)
{
if(v1>v3)
{
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Party A wins");
delay(1500);
votedifference();
}
else if(v3>v1)
{
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Party C wins");
delay(1500);
votedifference();
}
}
else
{
if(v2>v3 && v1!=v2)
{
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Party B wins");
delay(1500);
votedifference();
}
else if(v3>v2)
{
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Party C wins");
delay(1500);
votedifference();
}
}
}
// infinite loop starts from this point for serial data reception
while(1)
{
while(RI==0); // wait until some data byte is received serially
temp=SBUF; // store the data byte in the temporary variable
RI=0; // clear te RI flag for next data byte reception
#include <LiquidCrystal.h>
char temp[50];
int m;
int inByte =0;
void setup()
{
// initialize serial communication with baud rate of 9600 bps
Serial.begin(9600);
// wait for a while till the serial port is ready
delay(100);
// configure the gsm modemin sms mode
Serial.print("AT+CMGF=1\r");
delay(500);
// route the contents of the received sms on to serial port
Serial.print("AT+CNMI=2,2,0,0,0\r");
// initialize 20X4 the lcd
lcd.begin(20, 4);
//print inittial message on lcd
lcd.print("**Device Control..**");
//define pins 2 ad 3 as o/p pins
pinMode(2,OUTPUT);
pinMode(3,OUTPUT);
// make default status of pin 2 and 3 low
digitalWrite(2,LOW);
digitalWrite(3,LOW);
delay(500);
}
// loop function starts here
void loop()
{
// clear the temporary variable temp
m=0;
for(m=0;m<45;m++)
{
temp[m]=0;
}
// wait for the reception of the message
// " is a identifier for the start of the message
do
{
while ( !Serial.available() );
} while ( '"' != Serial.read() );
// read the sms which will have date, time, sms body and the senders number
for(m=0;m<45;m++)
{
while ( !Serial.available() );
inByte = Serial.read();
temp[m]=inByte;
}
// after testing it is found that the main body of the sms willl start from psition 42 ie. for
m=42
// I have used 3 digit code for the sms and so position 42, 43 and 44 will contain the main
body of the sms
// print the received sms main body on the lcd screen
for(m=42;m<45;m++)
{
lcd.print(temp[m]);
}
/*codes are
D1N----------device 1 on
D1F----------device 1 off
D2N----------device 2 on
D2F----------device 2 off
DAN----------all devices on
DAF----------all devices off
*/
// device 1 is connected to pin 2 and device 2 is connected to pin 3 of the arduino