Hi everyone, I’m currently doing a project which is using an RFID reader and solenoid,
a little introduction to my project would be:
- Place a RFID tag at the RFID reader
- RFID reads tag and check for validation
3.If valid solenoid would be powered for 7sec - After 3sec solenoid will be powered off again.
Here is the components that I’ve used:
Grove - 125khz RFID Reader
Grove - Relay
Grove - Base shield
Arduino UNO
Solenoid 12V
I was able to make the code work individually for
the solenoid (powering up for 7sec and off it after 3sec)
and for the RFID reader (Reading that tags and getting information of it)
But I do not know how to combine both code together to make my project works.
Code for solenoid:
[code]const int solenoid = 2; //Set solenoid at pin 2
void setup()
{
pinMode (solenoid, OUTPUT);
}
void loop()
{
digitalWrite(solenoid, HIGH);
delay(7000);
digitalWrite(solenoid, LOW);
delay(3000);
}
[/code]
Code for RFID reader
[code]#include <SoftwareSerial.h>
SoftwareSerial SoftSerial(2, 3);
unsigned char buffer[64]; // buffer array for data receive over serial port
int count=0; // counter for buffer array
void setup()
{
SoftSerial.begin(9600); // the SoftSerial baud rate
Serial.begin(9600); // the Serial port of Arduino baud rate.
}
void loop()
{
if (SoftSerial.available()) // if date is coming from software serial port ==> data is coming from SoftSerial shield
{
while(SoftSerial.available()) // reading data into char array
{
buffer[count++]=SoftSerial.read(); // writing data into array
if(count == 64)break;
}
Serial.write(buffer,count); // if no data transmission ends, write buffer to hardware serial port
clearBufferArray(); // call clearBufferArray function to clear the stored data from the array
count = 0; // set counter of while loop to zero
}
if (Serial.available()) // if data is available on hardware serial port ==> data is coming from PC or notebook
SoftSerial.write(Serial.read()); // write it to the SoftSerial shield
}
void clearBufferArray() // function to clear buffer array
{
for (int i=0; i<count;i++)
{ buffer[i]=NULL;} // clear all index of array with command NULL
}[/code]
I’ve also included an attachment of what my circuit looks like!
Please note that I’m fairly new to coding so I’m apologising in advance if I do not get your meaning for any explanation…