Tag: craft
Halloween Maker Projetct – Lego Minifig Mk. 2
by critter42 on Oct.31, 2013, under Arduino Projects, Crafts, Electronics
This is my LEGO Minifig Head Mk. 2
The original head was starting to get beat up pretty good, so I built a new one. As they are made out of solid Styrofoam, they get pretty warm, so I have a fan system to keep me cool. In the previous version, the fans were activated by a switch in my left LEGO hand and run by a battery pack in my pants pocket. While this worked, it was a chore to get in and out of, and I would usually require assistance getting the wires run and connected.
When I started building Mk. 2, I decided to try to eliminate that issue. I have taken an Arduino Uno and an Arduino Mega 2560 and connected them via two Nordic NRF24L01+ boards. The Uno has 3 switches and is run by a 9V battery. I am currently only using one, the other two are for future plans. When the pin connected to the fan switch goes high, it sends a code (the number 11 in this case) wirelessly to the receiving unit on the Mega. When the Mega receives that code, it closes a relay and starts the fans.
I used Maniacbug’s RF24 Library available on Github – https://github.com/maniacbug/RF24. I found the examples included with the library kind of hard to understand (I’m not a programmer), but I found this example – www.bajdi.com/rf24-library-revisited – and I got my project up and running.
The sketches I used (note, I had a lot of serial.print statements for debugging and I’ve commented most of those out):
For the sending unit:
#include <SPI.h>
#include “nRF24L01.h”
#include “RF24.h”
int msg[1];
RF24 radio(9,10); //define the CE and CSN Pins
const uint64_t pipe = 0xE8E8F0F0E1LL; //Send and receiving units addresses must match
int SW1 = 5;void setup(void){
Serial.begin(9600);
radio.begin(); // set up the radio
radio.openWritingPipe(pipe);} // Open the radio for sendingvoid loop(void){
if (digitalRead(SW1) == HIGH){
msg[0] = 11; // Code that is sent to the receiving unit
radio.write(msg, 1); // send code if Pin defined above is HIGH
// Serial.println(“Switch high”);}}
And for the receiving unit:
#include <SPI.h>
#include “nRF24L01.h”
#include “RF24.h”
int msg[1];
RF24 radio(48,53); //define the CE and CSN Pins
const uint64_t pipe = 0xE8E8F0F0E1LL; //Send and receiving units addresses must match
int relay = 7;void setup(void){
Serial.begin(9600);
radio.begin();
radio.openReadingPipe(1,pipe);
radio.startListening(); // Open radio in receive mode and start listening
pinMode(relay, OUTPUT);} // Set relay pin to OUTPUTvoid loop(void){
if (radio.available()){
// Serial.println(“Radio Available”);
bool done = false;
while (!done){
done = radio.read(msg, 1); // poll Radio
// Serial.println(msg[0]);
if (msg[0] == 11){ // if Radio receives ’11’ from sending unit, set relay pin high
delay(10);
digitalWrite(relay, HIGH);
// Serial.println(“Pin 22 High”);
}
else {
digitalWrite(relay, LOW);
// Serial.println(“Pin 22 Low”);
}
delay(10);}}
else{Serial.println(“No radio available”);}}
Here’s a short video of the system working:
The next plan is to wire a couple of other gadgets to the Mega and I have a relay board I will be using to control them.