DEV Community

Vinayak Tiwari
Vinayak Tiwari

Posted on

Dynamic Speed Limit Adjustment Based on Real-Time Weather Conditions

๐ŸŒฆ๏ธ Adaptive Traffic Science: Smart Speed Limit Controller ๐Ÿš—

Image description

Drive Safe, Drive Smart! A React.js prototype that dynamically adjusts speed limits based on real-time weather conditions โšก


๐Ÿš€ Features

  • ๐ŸŒฉ๏ธ Real-time Weather Detection (Rain/Drizzle)
  • ๐Ÿšฆ Dynamic Speed Adjustment (60 km/h in bad weather)
  • ๐Ÿ”„ Manual Refresh Button for instant updates
  • ๐Ÿ“ฑ Responsive UI with clean interface
  • ๐Ÿ”ง IoT-Ready Architecture for future expansion

๐Ÿ“‹ Table of Contents

  1. Overview
  2. Prerequisites
  3. Tech Stack
  4. Setup Guide
  5. How It Works
  6. Future Plans
  7. Contribution
  8. License

๐ŸŒ Overview

Image description

The Adaptive Traffic Science system automatically adjusts highway speed limits using live weather data:

  1. ๐Ÿ“ก Fetches weather data from OpenWeatherMap API
  2. โš ๏ธ Reduces speed to 60 km/h during rain/drizzle
  3. ๐Ÿ“Š Displays real-time updates in clean UI
  4. ๐Ÿ”„ Includes manual refresh capability

๐Ÿ› ๏ธ Prerequisites

Before getting started:

Requirement Description
๐Ÿ”‘ API Key OpenWeatherMap Account
โš›๏ธ React/TS Basic understanding of React & TypeScript
๐Ÿ–ฅ๏ธ Node.js Node.js v16+
๐Ÿ“ Editor VS Code recommended

๐Ÿ’ป Tech Stack

React TypeScript OpenWeatherMap Axios

Frontend       : React + TypeScript
API Integration: OpenWeatherMap API
HTTP Client    : Axios
Styling        : Pure CSS
Deployment     : Netlify/Vercel
Enter fullscreen mode Exit fullscreen mode

โš™๏ธ Setup Guide

1๏ธโƒฃ Clone Repository

git clone https://github.com/adaptive-traffic-science.git
cd adaptive-traffic-science
Enter fullscreen mode Exit fullscreen mode

2๏ธโƒฃ Install Dependencies

npm install
Enter fullscreen mode Exit fullscreen mode

3๏ธโƒฃ Configure API Key

Create a .env file:

REACT_APP_OPENWEATHERMAP_API_KEY=your_api_key_here
Enter fullscreen mode Exit fullscreen mode

4๏ธโƒฃ Start Development Server

npm start
Enter fullscreen mode Exit fullscreen mode

๐Ÿง  How It Works

๐Ÿ”‘ Key Components

Component Description
๐ŸŒค๏ธ WeatherDisplay Shows location, weather condition, and temperature
๐Ÿšฆ SpeedController Dynamically adjusts speed limit based on weather
๐Ÿ”„ RefreshButton Manual weather data refresh capability

โšก Core Logic

// SpeedLimitController.tsx
const determineSpeedLimit = (weatherCondition: string): number => {
  const SPEED_LIMITS = {
    NORMAL: 100,   // km/h
    REDUCED: 60    // km/h
  };

  return ['Rain', 'Drizzle'].includes(weatherCondition) 
    ? SPEED_LIMITS.REDUCED 
    : SPEED_LIMITS.NORMAL;
};
Enter fullscreen mode Exit fullscreen mode

๐Ÿ”ฎ Future Plans

  • ๐Ÿšจ IoT Integration: Connect with physical speed boards
  • ๐Ÿ—บ๏ธ Multi-Location Support: Track different highways
  • ๐ŸŒจ๏ธ Advanced Alerts: Snow/fog detection system
  • ๐Ÿ“Š Analytics Dashboard: Historical data visualization

๐Ÿค Contribution

We welcome contributions! Please follow these steps:

  1. Fork the repository
  2. Create a feature branch: git checkout -b feature/AmazingFeature
  3. Commit your changes: git commit -m 'Add some AmazingFeature'
  4. Push to the branch: git push origin feature/AmazingFeature
  5. Open a Pull Request

GitHub Repo: github.com/your-username/adaptive-traffic-science


๐Ÿ“œ License

This project is licensed under the MIT License - see the LICENSE.md file for details.

Top comments (0)

Sentry image

See why 4M developers consider Sentry, โ€œnot bad.โ€

Fixing code doesnโ€™t have to be the worst part of your day. Learn how Sentry can help.

Learn more