# Naughty or Nice Machine

## Overview

## It knows if you have been Naughty or Nice!
The Naughty or Nice machine is simply a bit of fun for the holidays. The machine works by taking a photo of the hand placed on the bottom plate. Using the openCV python computer vision library to count the number of red colour pixels, and display the result on the LCD screen. A little showmanship is used to entrain people while they are waiting for the results of the test. I created the “Naughty or Nice” machine for Christmas 2013, first of all I thought about hacking our Christmas tree, but everyone hacks their Christmas tree, then I had the idea for a “Naughty or Nice” meter, checked online and found that Ben Heck had beat me too that idea, sometime later I had the idea about making the meter interactive, and the idea for the “Naughty or Nice” machine was born.

![](https://cdn-learn.adafruit.com/assets/assets/000/021/704/medium800/leds_DSC_0446.jpg?1418681765)

The “Naughty or Nice” machine is built around the Raspberry Pi camera module, a Raspberry Pi model A, Adafrut USB/serial LCD screen and an Arduino driving RGB LEDs, Adafruit Neopixels. The project is cased in a frame made with Makerbeam and laser cut Perspex panels.

&nbsp;

# Naughty or Nice Machine

## Make It!

Info: 

If you're new to soldering have a look at this guide

[https://learn.adafruit.com/adafruit-guide-excellent-soldering](../../../../adafruit-guide-excellent-soldering)

The cable between the LV panel and it’s transformer plus the EL panel itself has a high potential (high voltage between 60 VAC to 120 VAC) be careful not to damage the cable and panel when installing it, see the Adafruit EL guide for details **&nbsp;**

[https://learn.adafruit.com/el-wire](../../../../el-wire)

# Parts

- Raspberry Pi
- Raspberry Pi camera module
- Adafruit USB/serial LCD display
- 2 x Adafruit Neopixel bars
- Arduino Uno
- RGB LED Arduino Shield - by Re-Innovation
- Adafruit blue EL panel plus power transformer
- buck converter or hacked car 12V&nbsp;to USB converter
- 12Vdc PSU &nbsp;2 amps or more
- 12V 2.1mm barrel socket
- 0.1” plug and sockets plus cable or you could use jumpers as required
- RGB LED strip
- short USB to micro USB lead
- stripbroad
- 2 x 10K resistors surface mount or through the hole
- 2 x 1K resistors or surface mount or through the hole
- 2 x push buttons

![](https://cdn-learn.adafruit.com/assets/assets/000/021/705/medium800/leds_DSC_0416.jpg?1418682065)

# The Case

I used Makerbeam for the frame and laser cut Perspex panels for the sides. You can use almost anything, from a cardboard box, wooden box or a fake ginger bread house, for your frame. The case should be at least 200mm high with a base large enough to fit a hand in. The Raspberry Pi is mounted on the top panel with the camera looking down and the Arduino is mount under the panel. The EL panel is mounted between the bottom panel and the base.

![](https://cdn-learn.adafruit.com/assets/assets/000/021/707/medium800/leds_DSC_0421.jpg?1418682354)

# The LCD screen

Solder together and test the USB/serial LCD kit, following the instructions here

[https://learn.adafruit.com/usb-plus-serial-backpack](../../../../usb-plus-serial-backpack)

![](https://cdn-learn.adafruit.com/assets/assets/000/021/708/medium800/leds_DSC_0409_%282%29.jpg?1418684232)

# Neopixel Sticks

Solder the two neopixal bars together, making sure that the power and data connections are same as in the photo. Solder 3 wires, to the 5v, 0v and data in connections, they need to be longer enough to connect to the Arduino.

![](https://cdn-learn.adafruit.com/assets/assets/000/021/710/medium800/leds_Giraffe-USB-4-larage.png?1418685439)

# Hacked Car USB Adaapter

Hack the car USB adapter, by removing the case and plug. Solder cables to the plug connection points, you removed, the centre pin is 12v and the side plates are ground (0v)

![](https://cdn-learn.adafruit.com/assets/assets/000/021/725/medium800/leds_switch.jpg?1418691308)

# The Switches

I used stripbroad and service mount resistors for the switches in this build, you can do the same or use through hole resistors. The copper has to be removed behind the 1K resistor.

# Naughty or Nice Machine

##  Preparing your Raspberry Pi

![](https://cdn-learn.adafruit.com/assets/assets/000/021/726/medium800/leds_DSC_0432.jpg?1418691826)

It is best to use the latest version of Raspbian you can find the latest version on the Raspberry Pi website, follow the instutions there. I personally like the noobs install method. When you have installed Raspbian, when your Raspberry Pi starts for the first time,&nbsp;the config apt starts, select advanced options and enable the i2c option, then enable the camera module, exit and make sure Raspbian is up to date by entering the following at the command line. Your Raspberry PI will need to be connected to the internet to do this and to download the required software and modules.

**_sudo apt-get update_**

**_sudo apt-get upgrade_&nbsp;**

Install the picamera python module, if you are using the latest version of Raspbian the picamera module is already installed. For instructions follow this guide on the Raspberry Pi website by following this link.

**&nbsp;** [http://www.raspberrypi.org/learning/python-picamera-setup/](http://www.raspberrypi.org/learning/python-picamera-setup/)

**&nbsp;** install the openCV python module by entering the following at the command line

**sudo apt-get install libopencv-dev**

**sudo apt-get install python-opencv**

&nbsp;download the bootup program plus the control program for the Raspberry Pi to your home folder from git. enter the follow at the command line

_ **wget https://github.com/Corteil/NorN\_4/archive/master.zip** _  
_ **unzip master.zip** _  
_ **cd master** _  
_ **cp NN-0-04-4.1.py ~/NN-0-04-4.1.py** _  
_ **cp NN-0-04-4.1.py ~/run.py** _  
_ **cd ~** _  
_ **sudo rm -r NorN\_4-master/** _  
_ **rm master.zip** _

Next we need to modify the rc.local file to start running run.py when the Raspberry Pi starts up. first of all we need to make a backup of the file, enter the following at the command line. **&nbsp;**

**_sudo cp etc/rc.local etc/rc.local.old_**

if you need to restore the old file enter enter the following at the command line

**&nbsp;** _ **sudo cp etc/rc.local.old etc/rc.local** _ **&nbsp;**

Now to modify the rc.local file by entering at the command line.

&nbsp;_ **sudo nano /etc/rc.local** _

and adding the following before "exit O"

_ **python /home/pi/run.py** _

and save by holding ctrl O, press enter to accept and then ctrl X to exit

follow the guide on the&nbsp;hobbytronics website to disable the console on the serial port.

[http://www.hobbytronics.co.uk/raspberry-pi-serial-port](http://www.hobbytronics.co.uk/raspberry-pi-serial-port)

# Naughty or Nice Machine

## Preparing your Arduino

![](https://cdn-learn.adafruit.com/assets/assets/000/021/727/medium800/leds_DSC_0433.jpg?1418692151)

Install Arduino&nbsp;and add the Adafruit libraries for the Adafruit\_WS2801.h and Adafruit\_NeoPixel.h for Arduino. you can find them&nbsp;at&nbsp;https://github.com/adafruit

If you are new to the world of Arduinos, I would suggest that you follow the first few guides by Simon Monk&nbsp;on the learn.adafruit.com starting with the first lession.

[https://learn.adafruit.com/category/learn-arduino **&nbsp;**](../../../../category/learn-arduino "https://learn.adafruit.com/category/learn-arduino")

next&nbsp;upload NorN\_4.ino&nbsp;sketch to your Arduino using your normal method. You can download sketch from here

[https://github.com/Corteil/NorN\_4](https://github.com/Corteil/NorN_4)

&nbsp;install the RGB strip shield, contect the RGB strips to the shield and NeoPixel sticks. you will not be able to test until the Arduino and Raspberry Pi are conected together.

NOTE: you could use just a NeoPixel strip instead of the RGB shield and RGB strip, the Arduino sketch would required adjusting if this was done.

Connect the Arduino SDA and SCL lines to the Raspberry Pi plus connect grounds&nbsp;of both devices together.

# Naughty or Nice Machine

## Putting It All together

![](https://cdn-learn.adafruit.com/assets/assets/000/021/728/medium800/leds_DSC_0445.jpg?1418692216)

Build your case, fixing the Raspberry PI, Arduino, LCD display, Neopixals plus the RGB strip in place.

The EL panel is installed behind the transparent blue base in my case, this is to protect it, take care with the power connections, making sure that the cable and joints are OK.

Connect the connected the RGB LEDs strips following the screen print markings to the shield, and the Neopixels 5V, 0V to the Arduino’s 5V, 0V and the data in is connected digital pin 12. Using the TLL serial connection on the LCD display, connect the JST cable to the backpack and then connect to the Raspberry Pi's GPIO pins as follows: Red wire goes to +5V, Black wire goes to Ground, White data wire goes to pin 6 (TxD) or you can solder a header on and use jump wires instead.

![](https://cdn-learn.adafruit.com/assets/assets/000/021/729/medium800/leds_DSC_0424.jpg?1418692767)

Fit the power socket and connect with wires to the power in on the Arduino shield, and also feed the hacked 12v to USB converter or the buck converter, use the USB lead to power the Raspberry Pi from the usb socket on the USB converter. Connect the feed for the EL transformer to the socket, you may need to use some form of connector blocks to be connect all the required feeds.  
  
Connect the Arduino SDA and SCL lines to the Raspberry Pi plus connect grounds&nbsp;of both devices together.

Fit and connect the switches, to the Raspberry Pi GPIO&nbsp;pins &nbsp;the red wires goes to a 3v3 pin and the black wires to a 0V pin, The first switch's&nbsp;signal&nbsp;wire is connected to pin 23&nbsp;and the second&nbsp;is connected to pin 24

# Naughty or Nice Machine

## How To Take a Reading

![](https://cdn-learn.adafruit.com/assets/assets/000/021/731/medium800/leds_DSC_0435.jpg?1418693062)

 **Instructions for use.**

&nbsp;

1. When the "Naughty or Nice" machine first starts press the bottom button.&nbsp;
2. Place hand on the bottom plate inside the machine, up to your wrist
3. Press bottom button
4. Remove hand when&nbsp;instructed
5. Wait for your Naughtness rating

![](https://cdn-learn.adafruit.com/assets/assets/000/021/730/medium800/leds_DSC_0438.jpg?1418692883)


## Related Guides

- [Knobby Sequencer](https://learn.adafruit.com/knobby-sequencer.md)
- [Adafruit Sparkle Motion](https://learn.adafruit.com/adafruit-sparkle-motion.md)
- [LED Protest Sign](https://learn.adafruit.com/led-protest-sign.md)
- [Chilled Drinkibot](https://learn.adafruit.com/chilled-drinkibot.md)
- [Darth Faders](https://learn.adafruit.com/darth-faders.md)
- [Air Quality Monitor and Case](https://learn.adafruit.com/aqi-case.md)
- [Star Fragment IoT Lamp](https://learn.adafruit.com/star-fragment-iot-lamp.md)
- [LED Acrylic Sign](https://learn.adafruit.com/led-acrylic-sign.md)
- [Adabot Toy Robot Friend](https://learn.adafruit.com/adabot-rp2040.md)
- [Solderless Robot Toy Xylophone](https://learn.adafruit.com/solderless-robot-toy-xylophone.md)
- [Bass MIDI Stomp Box](https://learn.adafruit.com/midi-bass-synth-stomp-box.md)
- [Adafruit Sparkle Motion Stick](https://learn.adafruit.com/adafruit-sparkle-motion-stick.md)
- [Stepper Motor Turntable](https://learn.adafruit.com/stepper-motor-turntable.md)
- [Bluetooth Controlled NeoPixel Lightbox](https://learn.adafruit.com/bluetooth-neopixel-lightbox.md)
- [Lighting LED Nets with WLED and xLights](https://learn.adafruit.com/lighting-led-nets-with-wled-and-xlights.md)
