RFID SWITCH ON LED & Dimmer control? Please Help.
I am making a prototype using a LED to represent a real light in the home but I can't get all my code to work together. If somebody could help me my Honours project will be complete. I want to scan a tag, tag switches on LED, MAX slider controls brightness of led. I have them all working individually but not together.
1.First I will show you the Arduino code for the RFID Reader.
2.Then Max patch for RFID Tag Reader
3.The Arduino code to switch on LED
4.The Max patch to switch on LED
5.The Arduino Code for the Led dimmer
6.The Max patch for the dimmer.
---------------------------
1.RFID code for Arduino: (http://hcgilje.wordpress.com/resources/rfid_id12_tagreader/)
---------------------------
/* RFID ID12
*/
char val = 0; // variable to store the data from the serial port
void setup() {
Serial.begin(9600); // connect to the serial port
}
void loop () {
// read the serial port
if(Serial.available() > 0) {
val = Serial.read();
Serial.write(val);
}
}
------------------------------
2.MAX Patch RFID Tag Reader:
------------------------------
copy and paste into maxmsp. You might want to clear the menu before adding your own tags:
-----------------------------------
3.Arduino Code to switch on LED:
(https://cycling74.com/forums/arduino-uno-max)
-----------------------------------
int maxData = 0;
void setup()
{
Serial.begin(9600);
pinMode((9), OUTPUT);
}
void loop()
{
while(Serial.available() > 0) {
maxData = Serial.read();
}
if(maxData == 1)digitalWrite(9, HIGH); // turn led on
}
----------------------------------
4.The Max Patch for turn on LED:
----------------------------------
--------------------------------------
5.The Arduino Code for the Led dimmer (http://arduino.cc/en/Tutorial/Dimmer)
--------------------------------------
const int ledPin = 9; // the pin that the LED is attached to
void setup()
{
// initialize the serial communication:
Serial.begin(9600);
// initialize the ledPin as an output:
pinMode(ledPin, OUTPUT);
}
void loop() {
byte brightness;
// check if data has been sent from the computer:
if (Serial.available()) {
// read the most recent byte (which will be from 0 to 255):
brightness = Serial.read();
// set the brightness of the LED:
analogWrite(ledPin, brightness);
}
}
----------------------------------------
6.The Max patch for the dimmer.
----------------------------------------
No time to check all those codes, but I have one remark: you seem to get both the rfid datas and Max datas from the serial port. I think it is possible (although I can't check now) to get serial datas over the IO pins 0 & 1 AND over the USB port, but then you need a way to identify which device sent the message you received.
Or you need to use other IO pins as a serial port, which is a standard feature with the arduino 1.0 IDE (see SoftwareSerial in the examples).
p
Even if I could just switch on the led with RFID without the dimmer would still be great.
What Patrick says is correct, you need more than a simple SerialRead if you are using more than one serial input, and you should follow his link.
Do you specifically need Max for some reason? You can just use RFID and Arduino to switch on the LED and then hook up a potentiometer to dim.
Me and Arduino are a bit rusty, but this might be how to switch on the LED with RFID (obviously replace desiredTagNumber with the tag ID you are using):
char val = 0; //variable to store the data from the serial port
void setup() {
Serial.begin(9600); //connect to the serial port
}
void loop() {
if (Serial.available() > 0) {
val = Serial.read();
if (val == desiredTagNumber){
digitalWrite(9, HIGH);
}
}
}
Yeah tried that bit of code but no joy. I need to use MAX as my project relies on using my phone to control the light. I have a RFID chip on the back so I need to scan, light turns on then phone control light. I just can't get RFID, led high, and the dimmer working together. does anybody know a quick read tag, turn on led, read tag turn off led. I have tried using processing too but with no joy. It is like making a Frankenstein RFID light. any more help would be amazing. been spending weeks on this. is there any way to get RFID and Maxuino working together?? I can make them all work great individually but I want my Demo to be consistent without opening up new codes and attaching new Arduinos.
Thanks so much for the replies so far.
Keenbop
OK, personally if I wanted to do this, I would still do it all on Arduino. I would use a wifi enabled Arduino (wifi shield or something like the diamondback or hydrogen from DIY sandbox) and then either:
1. serve a webpage from the arduino that enables you to control the light from a browser on your phone
2. use an OSC app like TouchOSC and send OSC to the wifi arduino to control the light
There are tutorials for doing exactly these things on the DIYsandbox website, and the Asynclabs website and the Arduino forum.
This leads me to wonder why you need RFID too? Isn't an on/ off button on the phone interface enough? If you really want to use Max, then you are going to have to follow the advice you were given and examine your serial issues.
If you mention the problems you get with the code I gave you then I/ someone else might be able to help you, though you might want to head over to the Arduino forum.