Introduction: No TV Unless You Exercise!

When I was a kid, I went to a science museum where there was a TV powered by a stationary bike that was hooked up to a generator. I’ve always thought it would be great if every TV worked that way- it would improve your health and use green energy.

This past winter I was looking for a way to stay in shape and I found an inexpensive bike stand that let me pedal my bike indoors. It worked fine but it was pretty boring, and I have trouble exercising when I'm not motivated. I remembered the TV powered by a bike and thought, "Yeah! THAT would make me want to keep going."

Well it turns out generators are pretty expensive, and turning your TV on and off repeatedly probably isn't good for it. So I made something that does the other part of the job- it makes the TV go dark unless you keep pedaling.

Update: added video of it in action

Step 1: Overview

The system has three components- a detector, an Arduino Nano, and a relay. The relay is hooked up inline to an RCA cable going from a video source to the TV. The Arduino looks for input from the detector, and if it doesn’t receive a signal within a certain amount of time (I’m using 10 seconds), it turns off the relay which opens the circuit and the input to the TV goes dark. I have a warning buzzer that goes off when there’s 2 seconds left in the countdown.

The detector I’m using is a black/white detector normally used for robot line following. I put a strip of black and white tape on the back wheel of my bicycle, which is attached to the bike stand. The Arduino is looking for BOTH black and white detections from the wheel (it is set to look for both so that you can't just position the wheel in a certain way to keep the video on). If it doesn't see both in 10 seconds, it activates a relay that turns off the video to the TV. Note- it doesn’t turn off the DVD player or the TV, it just disconnects the input until the pedaling starts again.

Once I had the code figured out, the only really tricky part was aligning the detector in the right place. You want it to be close to the wheel but not touching. I originally tried using a Hall magnetic detector, but I couldn't get it close enough to detect without it connecting occasionally.

Step 2: The Equipment

The bike stand is this one from Amazon: Amazon link

The sensor is a black/white detector, roughly $4.00 from ebay: ebay link

The Arduino is a Nano, but you could probably use any type: ebay link

The relay is a 5V relay, like this one: ebay link.

The input is a standard RCA cable like this one: Amazon link

The wires are standard F-F breadboard wires like this: ebay link

I don't remember where I got the LED or the buzzer, but they're basic stuff, and they're optional. I also used a mini breadboard but just about any would do

Step 3: Wiring

The logic flow for this is: bike -> sensor -> Arduino -> relay -> TV input

The Arduino wiring shown is as follows:

Red: 5V power to relay

Brown: GND to relay

Orange: D3 control wire to relay


Blue: 3.3V power to detector

Green: GND to detector

Yellow: D12 input from detector


Detection LED: D11 to ground (optional)

Buzzer: D4 to ground (optional, would work with an LED too)

Step 4: RCA Cable Setup

Cut a standard RCA cable in half, and strip the ends. Inside the outer insulation will be an insulated inner wire and an un-insulated outer wire. Twist the outer wires together. Strip the inner wires, and put them in to the NO and COM terminals of the relay. Hook the RCA ends of the cables up in line between the video source and the TV. Now the video won't be able to go to the TV unless the relay is closed.

Step 5: The Code

Here's the logic behind the code: there are 2 "counter" variables- one for white detection and one for black. At the beginning, they're set to "countmax", which here is 10 seconds. Every 10 milliseconds, the Arduino looks for either a high or low detection, and it sets the counter for what it finds back to countmax while the other counter drops by 10. If either counter drops below "countwarn" (2 seconds), the buzzer sounds. If either counter drops below zero, it turns off the relay so the signal on the RCA cable is opened and nothing goes to the TV.

You can edit the variables to set the max and warning times. There are lots of Instructables here about uploading an .ino file to the Arduino. I'm using a Nano, but the Uno or any other should probably work. There must be better ways to write the code, but I'm a civil engineer not a computer programmer.

If I've done it right, bikerelay.ino is attached and that's the code you need (could somebody put it on github?). Here's the ugly text version if that didn't work:

int ledpin = 13; //activates arduino light when there's a detection
int ledpin2 = 11; //activates external LED or buzzer when there's a detection int outputpin = 3; //pin the relay control is attached to int sensorpin = 12; //pin the detector is attached to int warnpin = 4; //pin used to activate warning LED or buzzer int counter = 0; //countdown since last detection int counter2 = 0; //countdown since last non-detection

//change the next 2 settings to adjust the timer intervals int countmax = 10000; //maximum level of countdown timer. 1000 = 1 second int countwarn = 2000; //when to turn on warning pin. 1000 = 1 second void setup() { pinMode(ledpin, OUTPUT); pinMode(ledpin2, OUTPUT); pinMode(outputpin, OUTPUT); pinMode(warnpin, OUTPUT); pinMode(sensorpin, INPUT); counter = countmax; counter2 = countmax; //any line with "serial" is for debugging and should be commented out if not needed because it will slow the clock down //Serial.begin(9600); //Serial.print("count: "); //Serial.println(counter); //Serial.print("count2: "); //Serial.println(counter2); } void loop() { if ( digitalRead(sensorpin) ) //what to do when there is a non-detection { digitalWrite(ledpin,LOW ); digitalWrite(ledpin2,LOW ); counter = counter - 10; counter2 = countmax; } else //what to do when there is a detection { digitalWrite(ledpin,HIGH); digitalWrite(ledpin2,HIGH); counter = countmax; counter2 = counter2 - 10; }

//serial output lines for debugging //Serial.print("count: "); //Serial.println(counter); //Serial.print("count2: "); //Serial.println(counter2); //Serial.println("-----------"); //sound a warning if either counter is above 0 but under the "countwarn" level if ( counter > 0 && counter < countwarn || counter2 >0 && counter2 < countwarn) { digitalWrite( warnpin,HIGH ); } else { digitalWrite( warnpin,LOW ); }

//turn off the output if either counter drops below 0 //these settings are for an "active low" relay. Switch "HIGH" and LOW for an active high output if ( counter < 0 ) { digitalWrite(outputpin,HIGH ); counter = 0; } else if ( counter2 < 0) { digitalWrite(outputpin,HIGH ); counter2 = 0; } else { digitalWrite( outputpin,LOW ); }

delay(10); // wait time (miliseconds) before going again


Step 6: The Results

When you start pedaling, the relay will close and the video will go to the TV. If you stop pedaling for 8 seconds, the alarm will sound. Two more seconds, and the relay will open and no more TV for you. Back to pedaling!!

It would be pretty easy to add this to a treadmill too- just put a strip of white electrical tape on the tread and point the black/white detector at it. If you wanted to get really fancy you could hook it up to a weight set too.

If you build this and like it, it would be nice if you would make a small donation to your local Humane Society.

Thanks for reading!

Coded Creations

Third Prize in the
Coded Creations

Bicycle Contest

Participated in the
Bicycle Contest