Simple Record and Playback © CC BY-NC-SA

Record and play back a few seconds of input stored in EEPROM.

  • 3,985 views
  • 3 comments
  • 39 respects

Components and supplies

Apps and online services

About this project

This project allows you to "record" sensory input and store it for later use. The information is stored in EEPROM instead of dynamic memory so that it can be remembered even when the board is shut down (like a tiny hard drive).

Materials:

As an Amazon Associate I earn from qualifying purchases.

Step 1: Make the Circuit

Make the circuit according to the diagram above:

  • Potentiometer to pin A0
  • Button to pin D2
  • Servo to pin D3
  • Led to pin D13

See a circuit simulation here!

Step 2: Upload Code

Upload this code to your Arduino (no additional library installations required):

#include <Servo.h>
#include <EEPROM.h>//used to store recorded values
Servo myServo;
float resolution = 1000;//MUST be less than EEPROM.length()
float recordTime = 5; //delay time
bool recording = false;
void setup() {
 pinMode(13, OUTPUT); //status led
 pinMode(2, OUTPUT);
 myServo.attach(3);
 Serial.begin(9600);
 digitalWrite(2, HIGH);
 //Serial.println(EEPROM.length());
}
void loop() {
 if (recording == true) {//record
   for (int i = 1; i <= resolution; i++) {
     digitalWrite(13, HIGH); //light status led
     int val = map(analogRead(A0), 0, 1023, 0, 180);
     EEPROM.write(i, val);
     //Serial.println(EEPROM.read(i));
     myServo.write(val);
     delay(recordTime);
   }
   digitalWrite(13, LOW); //turn off status led
   delay(1000);//give time for person
   recording = false;
 }
 else {
   for (int i = 1; i <= resolution; i++) {//playback
     if (digitalRead(2) == 0) {//stop playback and record new values
       recording = true;
       break;
     }
     int readval = EEPROM.read(i);
     myServo.write(readval);
     //Serial.println(readval);
     delay(recordTime);
   }
   digitalWrite(13, HIGH); //show a new repeat
   delay(100);
   digitalWrite(13, LOW);
 }
}

Note the comment that says //MUST be less than EEPROM.length()

To find the size of your board's EEPROM storage, uncomment the line //Serial.println(EEPROM.read(i)); This will print the size of EEPROM in the serial monitor, and you can change the value of the noted variable accordingly.

How to Use

To use this circuit, you simply press the button to begin recording and input the desired information through a potentiometer. Now, the board will repeat your actions endlessly (and it blinks an led each iteration) until you press the button again to record new actions. You may also vary the amount of time recorded by changing the values of resolution and recordTime.

Notes

This code uses a ton of EEPROM memory on the Arduino, so are some solutions:

  • Instead of a "smooth" recording, you could just have it record one position at a time and have it be more "jumpy." Just move the servo to a new position and press a button to keep it. Do this until you have all the positions you want.
  • Store in PROGMEM (program memory) instead of EEPROM
  • Use a regular integer array instead of EEPROM if you don't need to save information during a power loss.
  • Write to external storage such as a microSD card

Code

CodeArduino
#include <Servo.h>
#include <EEPROM.h>//used to store recorded values

Servo myServo;

float resolution = 1000;//MUST be less than EEPROM.length() (check serial monitor)
float recordTime = 5; //delay time
bool recording = false;

void setup() {
  pinMode(13, OUTPUT); //status led
  pinMode(2, OUTPUT);
  myServo.attach(3);

  Serial.begin(9600);
  digitalWrite(2, HIGH);
  //Serial.println(EEPROM.length());
}

void loop() {
  if (recording == true) {//record
    for (int i = 1; i <= resolution; i++) {
      digitalWrite(13, HIGH); //light status led
      int val = map(analogRead(A0), 0, 1023, 0, 180);

      EEPROM.write(i, val);
      //Serial.println(EEPROM.read(i));
      myServo.write(val);
      delay(recordTime);
    }

    digitalWrite(13, LOW); //turn off status led
    delay(1000);//give time for person
    recording = false;
  }
  else {
    for (int i = 1; i <= resolution; i++) {//playback
      if (digitalRead(2) == 0) {//stop playback and record new values
        recording = true;
        break;
      }
      int readval = EEPROM.read(i);
      myServo.write(readval);
      //Serial.println(readval);
      delay(recordTime);
    }

    digitalWrite(13, HIGH); //show a new repeat
    delay(100);
    digitalWrite(13, LOW);
  }
}

Schematics

Schematic
Record and play nqukgxddi0

Comments

Similar projects you might like

DIY Auto Voice Record and Playback

Project tutorial by Team gadgetprogrammers

  • 1,985 views
  • 3 comments
  • 13 respects

Simple Obstacle Sensor with Arduino

Project tutorial by muhammed shameel k.v

  • 4,631 views
  • 2 comments
  • 7 respects

Simple Homemade Flex Sensor

by Shahir nasar

  • 4,358 views
  • 1 comment
  • 9 respects

Simple wall clock using Adafruit 1/4 60 Ring Neopixel

Project tutorial by antiElectron

  • 7,774 views
  • 2 comments
  • 37 respects

Simple UNO calculator

Project tutorial by Joprp05

  • 6,350 views
  • 0 comments
  • 6 respects

Arduino Simple "Camera Slider" Electronics

Project tutorial by Ian Cumming

  • 6,278 views
  • 3 comments
  • 17 respects
Add projectSign up / Login