A professional web-based Arduino simulator with real-time hardware simulation and code generation
FOSSEE OSHW Winter Internship – 2025 Screening Task
Features • Installation • Usage • Architecture • Technology Stack
- Overview
- Features
- Technology Stack
- Architecture
- Installation
- Usage
- Project Structure
- Engineering Implementation
- Development
- Contributing
This project is a professional-grade web-based Arduino simulator that enables users to build, configure, and simulate Arduino circuits entirely in the browser. Built as part of the FOSSEE OSHW Winter Internship screening process, it demonstrates advanced web engineering techniques combined with embedded systems simulation.
- Visual Circuit Design: Drag-and-drop interface for building Arduino circuits
- Real-Time Code Generation: Automatic Arduino code generation based on circuit configuration
- Hardware Simulation: Logic-level simulation using avr8js CPU emulation
- Pin Configuration: Dynamic pin assignment with mutual exclusion validation
- Live Visualization: Real-time hardware component rendering using Wokwi elements
- Component Palette: Drag-and-drop component library (Arduino UNO, LED, Push Button)
- Interactive Canvas: Repositionable components with visual pin labels
- Dual View Modes: Switch between Component View and Code View seamlessly
- Properties Panel: Configure component pins with validation and mutual exclusion
- Syntax Highlighting: Professional C++/Arduino code display with syntax highlighting
- CPU-Level Simulation: Uses avr8js for instruction-level AVR CPU emulation
- Register Manipulation: Direct DDR and PORT register control for GPIO simulation
- Real-Time Execution: requestAnimationFrame-based simulation loop (~16MHz equivalent)
- Port Mapping: Direct mapping between Wokwi components and AVR I/O ports
- Dynamic Re-binding: Instant pin reconfiguration without simulation restart
- Auto-Generated Arduino Code: Real-time code generation based on circuit configuration
- Pin-Aware Generation: Code automatically updates when pins are reconfigured
- Arduino Standard: Generates standard Arduino
setup()andloop()structure - INPUT_PULLUP Support: Proper pull-up resistor configuration for buttons
- React 18.2.0 - Modern UI library with hooks and functional components
- Vite 5.0.0 - Next-generation build tool for fast development and optimized production builds
- avr8js 0.20.1 - JavaScript implementation of AVR 8-bit microcontroller
CPU- AVR CPU core emulationAVRIOPort- GPIO port modeling (Port B, C, D)avrInstruction()- Instruction-level executionportBConfig,portCConfig,portDConfig- Port configuration
- @wokwi/elements 1.9.1 - Web Components for hardware visualization
<wokwi-arduino-uno>- Arduino UNO board visualization<wokwi-led>- LED component with color and state control<wokwi-pushbutton>- Interactive push button component
- react-draggable 4.5.0 - Drag-and-drop functionality for components
- react-syntax-highlighter 15.5.0 - Code syntax highlighting (VS Code Dark+ theme)
- @vitejs/plugin-react 4.2.0 - Vite plugin for React support
- @types/react 18.2.0 - TypeScript definitions for React
- @types/react-dom 18.2.0 - TypeScript definitions for React DOM
- intel-hex 0.2.0 - Intel HEX file format parser (for future HEX loading support)
- Component-Based Architecture: Modular React components
- State Management: React hooks (useState, useRef, useCallback, useEffect)
- Event-Driven Simulation: requestAnimationFrame for real-time updates
┌─────────────────────────────────────────────────────────────┐
│ User Interface Layer │
│ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐ │
│ │ Component │ │ Code View │ │ Properties │ │
│ │ Canvas │ │ Panel │ │ Panel │ │
│ └──────────────┘ └──────────────┘ └──────────────┘ │
└─────────────────────────────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────┐
│ Application Logic Layer │
│ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐ │
│ │ Component │ │ Pin │ │ Code │ │
│ │ Manager │ │ Configurator │ │ Generator │ │
│ └──────────────┘ └──────────────┘ └──────────────┘ │
└─────────────────────────────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────┐
│ Simulation Engine Layer │
│ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐ │
│ │ AVR8js CPU │ │ I/O Port │ │ Simulation │ │
│ │ Emulator │ │ Manager │ │ Loop │ │
│ └──────────────┘ └──────────────┘ └──────────────┘ │
└─────────────────────────────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────┐
│ Hardware Visualization Layer │
│ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐ │
│ │ Wokwi │ │ Wokwi LED │ │ Wokwi │ │
│ │ Arduino UNO │ │ Component │ │ Push Button │ │
│ └──────────────┘ └──────────────┘ └──────────────┘ │
└─────────────────────────────────────────────────────────────┘
- User Interaction → Component drag/drop, pin configuration
- State Update → React state management updates component/pin configuration
- Code Generation → Arduino code generated based on current state
- Simulation Start → AVR8js CPU initialized with port configuration
- Simulation Loop → CPU executes instructions, I/O ports updated
- Visual Update → Wokwi components reflect CPU port states
User Action (Button Press)
↓
handleButtonPress()
↓
AVRIOPort.setPin() → Updates CPU PIN register
↓
Simulation Loop reads PIN register
↓
Calculates LED state (inverted button state)
↓
AVRIOPort.setPort() → Updates CPU PORT register
↓
Port Listener detects PORT register change
↓
setLedStates() → Updates React state
↓
<wokwi-led> value prop updates
↓
Visual LED turns ON/OFF
- Node.js 16.x or higher
- npm 7.x or higher (or yarn / pnpm)
-
Clone the repository
git clone <repository-url> cd FOSSEE-OSHW
-
Install dependencies
npm install
-
Start development server
npm run dev
-
Open in browser
- The application will automatically open at
http://localhost:3000 - Or manually navigate to the URL shown in the terminal
- The application will automatically open at
npm run buildThe production build will be created in the dist/ directory.
npm run preview-
Add Components
- Drag Arduino UNO from the sidebar to the canvas
- Drag LED (Red) to the canvas
- Drag Push Button to the canvas
-
Configure Pins
- Click on the LED component
- Open the PROPERTIES tab
- Select a pin from the dropdown (default: D10)
- Click on the Push Button component
- Select a pin from the dropdown (default: D2)
-
View Generated Code
- Switch to Code View or open the CODE (ino) tab
- Observe the auto-generated Arduino code with your pin configuration
-
Run Simulation
- Click Start Simulation button
- Press and hold the push button
- Observe the LED turning ON when button is pressed
- Release the button to turn the LED OFF
-
Reconfigure Pins
- While simulation is running, change pin assignments in Properties
- Simulation automatically rebinds to new pins without restart
- Available Pins: Digital pins D2 through D13
- Mutual Exclusion: Each pin can only be assigned to one component
- Dynamic Updates: Pin changes reflect immediately in code and simulation
FOSSEE-OSHW/
│
├── src/
│ ├── App.jsx # Main application component
│ ├── App.css # Global application styles
│ ├── ArduinoSimulator.jsx # Core simulator component
│ └── main.jsx # Application entry point
│
├── index.html # HTML template
├── vite.config.js # Vite configuration
├── package.json # Project dependencies and scripts
└── README.md # Project documentation
-
ArduinoSimulator.jsx- Main simulator component containing:- Component management logic
- Pin configuration system
- Code generation engine
- Simulation loop with avr8js integration
- Port mapping and I/O handling
-
App.jsx- Root component wrapper -
main.jsx- React application entry point
The simulator uses avr8js to directly manipulate AVR microcontroller registers:
// LED Pin Configuration (OUTPUT)
ledPort.setDDR(ledBit, true); // Set Data Direction Register
// Button Pin Configuration (INPUT_PULLUP)
buttonPort.setDDR(buttonBit, false); // Input mode
buttonPort.setPort(buttonBit, true); // Enable pull-up resistorThe simulation loop executes AVR instructions at logic-level speed:
// Execute ~16,000 instructions per frame (simulating 16MHz AVR)
for (let i = 0; i < instructionsPerFrame; i++) {
avrInstruction(cpu);
}LED state is derived from CPU PORT register, not React state:
// Read CPU PORT register (source of truth)
const portValue = ledPort.port;
const isHigh = !!(portValue & (1 << ledBit));
// Update UI based on CPU state
setLedStates(prev => ({ ...prev, [ledId]: isHigh }));Pin changes update CPU registers instantly:
// Reconfigure CPU registers with new pin assignments
setupCPURegistersDirectly(cpu, newLedPin, newButtonPin, portB, portC, portD);
// Update port listeners for new pins
ledPinListenerRef.current = () => {
const portValue = ledPort.port;
// Monitor new pin's PORT register
};- Frame Rate: 60 FPS (requestAnimationFrame)
- Instruction Rate: ~16,000 instructions per frame
- CPU Speed: Simulates ~16MHz AVR microcontroller
- Update Frequency: Port listeners check CPU state every frame
npm run dev- Hot Module Replacement (HMR) enabled
- Fast refresh for React components
- Automatic browser refresh on file changes
- JavaScript: ES6+ syntax
- React: Functional components with hooks
- Naming: camelCase for variables, PascalCase for components
- State Management: React hooks (useState, useRef, useCallback)
- Component Lifecycle: useEffect for simulation start/stop
- Performance: useCallback for expensive operations
- Refs: useRef for DOM elements and simulation engine references
This project was developed as part of the FOSSEE OSHW Winter Internship screening process. Contributions and improvements are welcome!
- Full HEX program loading and execution
- Additional components (sensors, displays, motors)
- Serial monitor integration
- Save/load circuit configurations
- Multi-board support
- Analog pin simulation
- Interrupt handling simulation
This project is developed for educational purposes as part of the FOSSEE OSHW Winter Internship program.
- FOSSEE - For the internship opportunity and screening task
- Wokwi - For the excellent hardware visualization components
- avr8js - For the powerful AVR CPU emulation library
- React Team - For the amazing frontend framework